Page 1 of 1
[Solved] CGBlog : current article id in articles'list ?
Posted: Tue Nov 22, 2011 8:47 pm
by Trangsene
Hello,
I have a site template displaying an article of the CGBlog and the list of the articles in a sidebar :
Code: Select all
<div id="sidebar">
{CGBlog summarytemplate='list'}
</div>
<div id="main">
{content}
</div>
In my list I have the following code just listing the articles :
Code: Select all
{foreach from=$items item=entry}
<ul>
<li><a href="{$entry->detail_url}">{$entry->title}</a></li>
</ul>
{/foreach}
How can I get the current article id in the template list in order to highlight his link with something like :
??
Thanks in advance for your help
Re: CGBlog : current article id in articles'list ?
Posted: Tue Nov 22, 2011 9:18 pm
by calguy1000
1. Your {content} block will have to be called before the 'list view' so that you can assign the variable and have it available for the list view.
Code: Select all
{content assign='mycontent'}
<div id="sidebar">
{CGBlog summarytemplate='list'}
</div>
<div id="main">
{$mycontent}
</div>
2. In your detail template you will need to assign a variable with the article id.
Code: Select all
{assign var='myarticleid' value=$entry->id}
3. In your summary template. You can use logic like:
Code: Select all
{if $myarticleid == $entry->id}...{/if}
Re: CGBlog : current article id in articles'list ?
Posted: Tue Nov 22, 2011 10:36 pm
by Trangsene
Thanks a lot for your help, it works fine.
But...
Now I lose my previous/next article navigation from my detail template, it disappears and I really don't understand why !
Code: Select all
{assign var='entryID' value=$entry->id}
{if isset($entryID) && $items|@count > 1}
{foreach from=$items item=entry2 name=idx}
{if $entryID eq $entry2->id}
{assign var=curpos value=$smarty.foreach.idx.index}
{/if}
{/foreach}
{assign var=next value=$curpos-1}
{assign var=prev value=$curpos+1}
<ul class="pagination">
{if $items[$next]}
<li class="next"><a href="{$items[$next]->detail_url}" title="{$items[$next]->title|strip_tags:false}">Next article ></a></li>
{/if}
{if $items[$prev]}
<li class="prev"><a href="{$items[$prev]->detail_url}" title="{$items[$prev]->title|strip_tags:false}">< Previous article</a></li>
{/if}
</ul>
{/if}
Do you have an idea where the problem is coming from ?

Re: CGBlog : current article id in articles'list ?
Posted: Wed Nov 23, 2011 10:26 am
by Trangsene
I've put my previous/next article navigation in a summary template and now the problem is solved.
Again thanks a lot calguy1000 for your quick and very clear answer !