Welcome Guest, Not a member yet? Register   Sign In
How can I have a counter using CI template parser?
#1

[eluser]behnampmdg3[/eluser]
Hi;

I use the code below and show the results in view no problems:
Code:
$posts_data=$this->blogs->list_posts($record_start);
$data_body = array( 'posts'=>$posts_data['posts']);
$this->parser->parse('home', $data_body);
And in View:
Code:
{posts}
<a class="posts_link" href="{url}blog/content/{BLOG_ID}">{BLOG_TITLE}</a> ({CATEGORY_TITLE})<br />
        {/posts}
I was wondering how I can add a counter to this list that shows numbers from 1 to .... Something like:
Code:
{posts}
{counter}<a class="posts_link" href="{url}blog/content/{BLOG_ID}">{BLOG_TITLE}</a> ({CATEGORY_TITLE})<br />
        {/posts}
I can easily do it with &lt;?php echo $counter++;?&gt; in view but I don't want to have php tags in my view.
Thanks
#2

[eluser]obiron2[/eluser]
When you build the dataset that gives you {BLOG_ID},{BLOG_TITLE} and {CATEGORY_TITLE} why not also collect {ROW_NUM}
If you are iterating a 2 dimensional array, can you use the array key value
e.g.
Code:
array(
      [0]=> array([BLOG_ID]=>17 [BLOG_TITLE]=>My First Post [CATEGORY_TITLE]=>Programming)
      [1]=> array([BLOG_ID]=>22 [BLOG_TITLE]=>My Second Post [CATEGORY_TITLE]=>Cookery)
)
#3

[eluser]TheFuzzy0ne[/eluser]
I agree. If you're against putting PHP tags into your view, then it would make more sense just passing in the counter already set the the appropriate value for the given entry, and not adding PHP logic to your view, and disguising it as being something other than PHP.




Theme © iAndrew 2016 - Forum software by © MyBB