Forum

Thread tagged as: Question

Variables in repeater attribures

Hey there

I'm trying to pass in an external variable to a template that contains a value to be used in the 'max' attribute in a repeater.

So, this works as expected:

<perch:repeater id="courses" label="Courses" max="5">

So, I am setting a variable and calling the template like this:

<?php
    PerchSystem::set_var('max_items', 3);
    $courses_items = perch_content_custom('Course List', array(
        'template'=>'courses_list.html',
    'return-html' => true,
    )); 
    print_r($news_items);
?>

And my template has this:

<perch:repeater id="courses" label="Courses" max="<perch:content id="max_items"/>">

I was expecting the value from 'max_items' to be used but it results in nothing being output at all. Can it actually be used in that way? If I put the perch:content elsewhere in the template, it outputs the number no problem, so I know that bit is working. I'm just not sure if I can use the value as a value for an attribute.

Hope all that makes sense!

Michael Wilkinson

Michael Wilkinson 6 points

  • 6 years ago

Michael, you can't use a tag within a tag. I have tried this sort of thing before. I am thinking what my solution was and if it comes to me I will post back. In the meantime I am sure Drew has a solution.

Robert Ketter

Michael Wilkinson

Michael Wilkinson 6 points
Registered Developer

Hi Robert

Yes that's what I thought but I thought I'd see if there was a way around. Thanks for the reply. Maybe if we combine heads we might have a solution in the distance!

Thanks again.

Michael

Drew McLellan

Drew McLellan 2638 points
Perch Support

There's no way to make that dynamic, currently.

Michael Wilkinson

Michael Wilkinson 6 points
Registered Developer

Ok, thanks Drew. I'll hard code it for now but I guess I can always return the data to an array and then output a set number if I need it.

Thanks, Michael