View previous topic :: View next topic |
Author |
Message |
sagi Smarty Regular
Joined: 30 Jul 2003 Posts: 43
|
Posted: Mon Sep 29, 2003 10:51 pm Post subject: variable inside config variables |
|
|
Is it possible to use a variable that was assigned from PHP inside a config variable?
For example, say I have a variable named back_arrow. In one design it might be:
back_arrow = "<"
But in the other design I want it to be:
back_arrow = '<img src="$imgurl/back_arrow.gif">'
Where $imgurl is the url assigned from a PHP script.
I tried that, I also tried {$imgurl} but it looks like smarty doesn't process those variables. Is there any way to do something like that? |
|
Back to top |
|
Enquest Smarty Regular
Joined: 14 May 2003 Posts: 79
|
Posted: Sun Oct 05, 2003 9:09 am Post subject: |
|
|
Yes why would it not be possible. For as far as I know, you need to define that in PHP not in Smarty.
And don't forget to $bakcarrow! don't forget the "$".
If you do an extra string in a string then you also can coconate.
$backarrow = $url . "/bjjljkd/" . $picture;
Good luck _________________ -----------------------
Learning my self by trying to help others |
|
Back to top |
|
sagi Smarty Regular
Joined: 30 Jul 2003 Posts: 43
|
Posted: Sun Oct 05, 2003 9:25 am Post subject: |
|
|
You don't understand, each design has another path to this image, but each design also has another images url, i need to combine the two inside the smarty config file (per design). |
|
Back to top |
|
fLowww Smarty Rookie
Joined: 30 Sep 2003 Posts: 7
|
Posted: Sun Oct 05, 2003 12:27 pm Post subject: |
|
|
If it comes from the URL and isn't assigned yet you should perhaps try this :
back_arrow = '<img src="{$smarty.get.imgurl}/back_arrow.gif">'
It is only an idea so plz don't shoot at me
greetz
fLo |
|
Back to top |
|
sagi Smarty Regular
Joined: 30 Jul 2003 Posts: 43
|
Posted: Sun Oct 05, 2003 1:35 pm Post subject: |
|
|
again, it has nothing to do with that - the problem is that the smarty config file doesn't interpret smarty commands, so you cant use any variables inside.
im still not sure what im gonna do, i might just use a smarty file with {var assign}'s instead or create an output filter. |
|
Back to top |
|
mikeken Smarty Regular
Joined: 13 Aug 2003 Posts: 57 Location: MN
|
Posted: Sun Oct 05, 2003 11:42 pm Post subject: |
|
|
If you keep shooting at people for nobody is going to help you.
Go to smarty.php.net there is a beginners tutorials somewheres there. Check it out and see if you can atleast get smarty working with the basics before you start using it like it works. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Mon Oct 06, 2003 12:28 am Post subject: |
|
|
hmmm. I don't think sagi was shouting. peace all.
@sagi: there was a thread on this topic awhile ago, but it fizzled out. Have you considered using eval? How about a modifier version of eval? |
|
Back to top |
|
sagi Smarty Regular
Joined: 30 Jul 2003 Posts: 43
|
Posted: Mon Oct 06, 2003 2:36 am Post subject: |
|
|
i'm not sure.. the designer will have to use those variables many times inside the code, and the eval syntax is just too long and will confuse him (it was hard enough to convince him to use it instead of the full image/dimensions at any place in the templates )
is there any reason why *not* to implement this? if it'll be compiled it won't effect the performance (unlike output filter) and i can see a demand for this feature.. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Mon Oct 06, 2003 8:40 am Post subject: |
|
|
I think that templated data is interesting. It has a lot of potential for 'abuse', though. Making the customizations to do it using the current config interface makes is a little tricky mainly because the smarty instance isn't passed to the config file class handler in the base config_load plugin. You can get similar functionality by by-passing config_load all-together and rolling your own plugin, I guess.
I dug up a version (I'm not even sure which) of the code I worked on that was mentioned in the other thread and got it working with the current cvs. It is far from perfect but the main problem is that you have to override config_load. That and the fact that I never tested it beyond a few simple test cases If interested, message me and I will send you a zip.
A more general interface to load data sets would be welcome |
|
Back to top |
|
sagi Smarty Regular
Joined: 30 Jul 2003 Posts: 43
|
Posted: Mon Oct 06, 2003 1:50 pm Post subject: |
|
|
i'm not sure that i understand the problem
first, whats wrong with fixing config_load? in my 2.6.0rc1 it looks like it is getting the smarty instance: smarty_function_config_load($params, &$smarty)
are the configs compiled like the normal template files? if yes, im not sure why will it be complicated to make smarty replace 'a`$var`b' with 'a'.$var.'b'.
i wouldn't mind getting a copy of your code, but i really need a solution within next few days so i might just go with {var} or an output plugin, is there any problem with using a config.tpl file with {var assign}'s instead of a config file? performance wise? |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Mon Oct 06, 2003 2:50 pm Post subject: |
|
|
the problem is that it doesn't pass that instance to class that actually processes the config file.
yeah, go with the safe bet
off-beat, but I don't see any big problems with assign templates if that's the way you want to go. |
|
Back to top |
|
sagi Smarty Regular
Joined: 30 Jul 2003 Posts: 43
|
Posted: Mon Oct 06, 2003 7:46 pm Post subject: |
|
|
hmm.. this is weird:
i have two files, config.tpl and test.tpl
config.tpl is:
Code: |
{assign var="arrow_back" value="<img src='`$dmediaurl`/arrow_back.gif' border='0' align='absmiddle' height='14' width='11'>"}
|
test.tpl is:
Code: |
{include file="config.tpl"}
{$arrow_back}
|
when i load test.tpl it outputs nothing. when i put {$arrow_back} in config.tpl i can see the value.
is this normal? any way to change this behavior?
i'm really thinking about just using an output filter with special variables with normal config file. the output filter will just run strtr() on the output. it shouldn't really effect the preformance, right? i mean, there are so many ob calls in the code already.. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
|
Back to top |
|
sagi Smarty Regular
Joined: 30 Jul 2003 Posts: 43
|
Posted: Mon Oct 06, 2003 9:38 pm Post subject: |
|
|
im not sure how that array solution would help me.
i'm going with the output plugin. if you add support for variables inside config files, the syntax would be: var = "a`$var`" right?
i'll just make the output filter replace few `$var`'s with the value, and will drop it once smarty supports it itself (one day, i hope ) |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Mon Oct 06, 2003 9:45 pm Post subject: |
|
|
I would expect {$var} syntax, but its your call, obviously.
The idea with the "array" solution is to allow data to be defined using a sparse syntax and in a way that they can be directly included into your templates resulting in data arrays. I implemented a more robust form of that technique on a production site to solve a problem similar to the one you described. I like it because it relegates things like caching and rebuild control to smarty and can be implemented entirely via the plugin API.
I wonder if Monte or Messju are even considering something along templated config files ?? |
|
Back to top |
|
|