2

I tried to use {{ page:slug }} as a parameter in my page to get the blog articles from the category of the same name. For example:

  • Pagename = About me
  • Slug = about-me

Then create a category with the same name and slugname in Blog with associated articles. Now in pagelayouts I thought I could create the following, but it doesn't seem to work. Does anyone know why not?

{{ blog:posts order-by="created_on" dir="asc" category="{{ page:slug }}" }}
<section class="title">
    <h4>
    {{ title }}
    </h4>
</section>
<section class="item">
    <p>{{ intro }}</p>
    <p><a href="{{ url }}">Read more..</a></p>
</section>
{{ /blog:posts }}

Solved

I found the answer by asking it face to face to another developer. Since this is a templating language, it doesn't support functionality. It just reads pre-made variables. So I will have to solve this problem by creating another method in pages/plugins.php.

Chris Visser
  • 1,607
  • 12
  • 24

3 Answers3

3

You don't need to try and embed a tag in a string, just pass the tag straight to the attribute.

{{ blog:posts order-by="created_on" dir="asc" category="{{ page:slug }}" }}

Should be:

{{ blog:posts order-by="created_on" dir="asc" category=page:slug }}

Easier than you thought ey?

Phil Sturgeon
  • 30,637
  • 12
  • 78
  • 117
1

This is how I solved it using PHP. The below edit checks if the page parameter from the {{ blog:posts }} tag is set. When it is, it grabs the last segment and uses it as category filter in the database query to retreive only those posts:

In system/cms/modules/blog/plugin.php look for the 'posts' function and add a parameter:

$page   = $this->attribute('page');

Then use the following statement to check if the parameter has been set and then add a 'where' statement:

if($page) //check if page is set
{
  $segment = end($this->uri->segment_array()); //get the last segment from the url
  $this->db->where('blog_categories.slug', $segment); //use the segment as filter
}

Now you can create a page containing blog posts from which the categories refer to its pagename like for example: www.website.com/pagename/subpagename/subsubpagename/awesome then use this as pagelayout and it will load a list of blogposts that have 'awesome' as category:

<h3>{{ page:title }}</h3>
{{ blog:posts order-by="created_on" dir="asc" page="true" }}


    <h4>{{ title }}</h4>

    <p>
        {{ intro }}</p>
    <p>
        <a href="{{ url }}">Read more..</a></p>

{{ /blog:posts }} 
Chris Visser
  • 1,607
  • 12
  • 24
0

Instead of using tags i have found a simple solution to avoid tags as much as we can. Here is it.

Instead of using tags call a view in plugin and pass the third parameter as TRUE so that it return string instead of loading view than do any kind of looping and conditional checking in the view as usuall as you do with php o course. No need to meet tags there. After that in plugin where you are calling this view simply return a single variable and use your variable in tags in the page to display content of view.
Here is an example

class Plugin_Home extends Plugin  
{  
    function test()  
    {
        $this->load->model('test/test_m');
        $data['test']   =   $this->test_m->index();
        return $this->load->view('test/test_view',$data , TRUE);
    }
}   

And in the page you can call it like this

{{ Home:test }}

And get rid of tags for conditioning and looping

Muhammad Raheel
  • 19,823
  • 7
  • 67
  • 103