Welcome Guest, Not a member yet? Register   Sign In
Troubles with Loops in Dwoo Parser
#1

[eluser]Clooner[/eluser]
I'm using phil's dwoo library and initial testing seems to be working fine. However I run intro trouble when I start using the loop function. Here is my code
Code:
{$myurl}
{loop $products title id}
<h1>{$title}</h1>
<a href="{$myurl}">Link</a>
{/loop}
The first $myurl get's loaded just fine but whenever I use the $myurl inside the loop I get an error saying it doesn't exist? This is my first time working with any template system so I might be doing it wrong but the dwoo documentation was not really helpful since it only has a real basic example on how to use loops. Hopefully someone here can explain me how to get the $myurl working inside the loop.
#2

[eluser]Mareshal[/eluser]
Code:
{$myurl}
{loop $products}
<h1>{$title} - {$id}</h1>
<a href="{$myurl}">Link</a>
{/loop}

read this: http://wiki.dwoo.org/index.php/Loop
#3

[eluser]Clooner[/eluser]
[quote author="Mareshal" date="1288744192"]
Code:
{$myurl}
{loop $products}
<h1>{$title} - {$id}</h1>
<a href="{$myurl}">Link</a>
{/loop}

read this: http://wiki.dwoo.org/index.php/Loop[/quote]

Thanks for the reply however I fail to see how this is different from my code since it outputs the same error! The problem is $myurl is not found inside the loop. The link you described also gives no hint about my problem which I also stated in my initial post. I believe I need to call $myurl inside the loop using some modification but I don't know how.
#4

[eluser]Mareshal[/eluser]
Paste the code from your controller, before calling parse()
#5

[eluser]Clooner[/eluser]
[quote author="Mareshal" date="1288747700"]Paste the code from your controller, before calling parse()[/quote]

That's simply
Code:
$data = array(
  'products' => array(
    array(
      'id' => 1,
      'title' => 'Titel 1'
    ),
    array(
      'id' => 2,
      'title' => 'Titel 2'
    )
  ),
'myurl' => 'http://testurl'
);
$this->load->library('parser');
$this->parser->parse('viewfile', $data);
#6

[eluser]cahva[/eluser]
Theres atleast 2 options. Either use {foreach} instead of {loop}:
Code:
{foreach $products product}
<h1>{$product.title} - {$product.id}</h1>
<a href="{$myurl}">Link</a>
{/foreach}

Or when using loop, use {$_.myurl} to get to parent scope
Code:
{loop $products}
<h1>{$title} - {$id}</h1>
<a href="{$_.myurl}">Link</a>
{/loop}

Check out the Shortcuts page.
#7

[eluser]Clooner[/eluser]
[quote author="cahva" date="1288753207"]Theres atleast 2 options. Either use {foreach} instead of {loop}:
Code:
{foreach $products product}
<h1>{$product.title} - {$product.id}</h1>
<a href="{$myurl}">Link</a>
{/foreach}

Or when using loop, use {$_.myurl} to get to parent scope
Code:
{loop $products}
<h1>{$title} - {$id}</h1>
<a href="{$_.myurl}">Link</a>
{/loop}

Check out the Shortcuts page.[/quote]

Thanks, that is what I needed to know... it's my first time using a template engine!




Theme © iAndrew 2016 - Forum software by © MyBB