• Welcome to the Chevereto user community!

    Here users from all over the world gather around to learn the latest about Chevereto and contribute with ideas to improve the software.

    Please keep in mind:

    • 😌 This community is user driven. Be polite with other users.
    • 👉 Is required to purchase a Chevereto license to participate in this community (doesn't apply to Pre-sales).
    • 💸 Purchase a Pro Subscription to get access to active software support and faster ticket response times.
  • Chevereto Support CLST

    Support response

    Support checklist

    • ⚠️ Got a Something went wrong message? Read this guide and provide the actual error. Do not skip this.
    • ✅ Confirm that the server meets the System Requirements
    • 🔥 Check for any available Hotfix - your issue could be already reported/fixed
    • 📚 Read documentation - It will be required to Debug and understand Errors for a faster support response

Passing variable from route php file to template

derekmlr

Chevereto Member
So, I've tried a few things, but no luck. Basically, trying to get a variable from the route php file to work in the template file. I've tried $handler::setVar('variable', $variable); but am unable to get <php echo $variable; ?> to work in the template :( Doesn't show anything (the value of $variable is string). What do I need to do to pass a variable from route to rendered template?

Thanks!
 
PHP:
$handler::setVar('variable', $variable);


Binds to:

PHP:
get_variable();
 
PHP:
$handler::setVar('variable', $variable);


Binds to:

PHP:
get_variable();
Ah. So, how would I bring a variable in route.*.php into it's template file? I tried this in the template...
Code:
<?php $content_type = get_variable('content_type'); echo $content_type; ?>
But it didn't seem to work.
 
In a route you use:

Code:
$handler::getVar('the_var');
Hmmm.

So, what I'm trying to do is...

* Set a variable in route (done easily)
* retrieve that variable in the template

For example, in route.user.php, there's a $type variable that returns a string ("images", "albums", etc). I want to make a conditional in the template (user.php) that applies the "current" CSS class if $type == "images".

Tried the setVar() to add it, but doesn't seem to work. I assume getVar() is for URI variables.

Thanks.
 
The system is quite easy to understand:

route.image.php:
PHP:
$handler::setVar("something",  "foo"); // sets "something" as "foo"

views/image.php
PHP:
echo get_something(); // prints "foo"

the getVar() is used within a route if you need to access to an already stored var so in theme files you always use get_something(). By the way, setVar can set anything not only URI variables (I don't know where you got that)
 
The system is quite easy to understand:

route.image.php:
PHP:
$handler::setVar("something",  "foo"); // sets "something" as "foo"

views/image.php
PHP:
echo get_something(); // prints "foo"

the getVar() is used within a route if you need to access to an already stored var so in theme files you always use get_something(). By the way, setVar can set anything not only URI variables (I don't know where you got that)
Ah, "get_<var_name>()" is what I needed. thanks! :)
 
Back
Top