Jump to content

How do I pass a variable to a a template file?


Aetherdan

Recommended Posts

Posted

The variable documentation seems a little lacklustre, and I can't seem to find any reference to how these variables are actually passed to the templates.

For example if I wanted to pass a variable i called $balance to a particular template file, how would i do so? I know that I can add it to the list of variables in the tempalte editor, but where do those variables actually get sent from?

Posted

It's lackluster from your perspective because it's not written for your purpose. It's about using variables already there, not adding new ones. 

You'd have to hook into the back end PHP code to alter the data before it is sent to the template.

WHAT template you're trying to modify data for, and what variable you're wanting to modify would be necessary to point you WHERE in the PHP back end you'd have to hook into to add in your data. 

Posted

So how would I hook a variable to a particular template in a theme?

For example what if I want to add my own variable to my own template theme?

Or add a variable from the "points" application that currently isn't in the available variables for a particular template file?

Posted

So, say you have your own template, your own PHP code, etc. Your variable is called $points.

\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'plugins', 'core', 'global' )->myTemplate( $points );

(This is in the context of a plugin for a template file called myTemplate)

<ips:template parameters="$points" />

<!-- Then in the template you can use the variable -->

Attempting to add a variable to an existing template is a bit more challenging and will depend upon the template, the backend code and other factors. You haven't provided a specific case you are attempting to adjust though, so I can't provide more guidance.

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...