ronaldatonline
ronaldatonline

Reputation: 37

PHP use defined globals within Smarty .conf text file

I have set a global var (STORE_PHONE_PICKUP_TIMES) in my php based webshop. The issue is to use it as described below. Tested several options to put the php global into the .html file via the .conf file. But not succeeded.

like:

define('STORE_PHONE_PICKUP_TIMES', '10:00-17:00');

file_name: shop_content.conf

[shop_content]
phone_pickup =  We are daily present at: {php} echo STORE_PHONE_PICKUP_TIMES{/php}

file_name: shop_content.html

<p>{#phone_pickup#}</p>

The result is: We are daily present at: {php} echo STORE_PHONE_PICKUP_TIMES{/php}

How can I get this GLOBAL into the .conf file using the setup as describe above.

Upvotes: 1

Views: 66

Answers (1)

r_a_f
r_a_f

Reputation: 649

It is not possible to use php in smarty config. And it is good because it force you to use better logic your app ;)

I suggest to use globals in templates:

<p>{#phone_pickup#} {$smarty.const.STORE_PHONE_PICKUP_TIMES}</p>

OR

store pickup hours only in config, it is good place for it (and separate from language string):

phone_pickup_hours = '10:00-17:00' phone_pickup = 'We are daily present at:'

now, in tpl it's easy: <p>{#phone_pickup#} {#phone_pickup_hours#}</p> but I assumed that you use define because you use this constant in other places for example in Controller layer so.. in php you can use config variable like this:

$pickup_hours = $smarty->getConfigVars('phone_pickup_hours');

Upvotes: 1

Related Questions