Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Insert Smarty variable in dynamic HTML

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
hansr
Smarty n00b


Joined: 22 Aug 2019
Posts: 3

PostPosted: Thu Aug 22, 2019 8:03 am    Post subject: Insert Smarty variable in dynamic HTML Reply with quote

Hello,

I want to insert a Smarty variable into a dynamic html string built in PHP. Something like:

Code:

$dynhtml='<b>Huisnummer: {$number} </b>';
$number="15";

$smarty->assign('dynhtml', $dynhtml);
$smarty->assign('number', $number);


The template:

Code:

{$dynhtml}


Unfortunately the variable $number is not parsed so the text "Huisnummer: {$number}" is printed.

Is it possible to construct dynamic html this way?

Thanks for your answers,

Regards,

Hans
Back to top
View user's profile Send private message
bsmither
Smarty Elite


Joined: 20 Dec 2011
Posts: 322
Location: West Coast

PostPosted: Fri Aug 23, 2019 7:09 am    Post subject: Reply with quote

Try in this order:
Code:
$number="15";
$smarty->assign('number', $number);

$dynhtml=$smarty->fetch('string:<b>Huisnummer: {$number} </b>');
$smarty->assign('dynhtml', $dynhtml);
Back to top
View user's profile Send private message
hansr
Smarty n00b


Joined: 22 Aug 2019
Posts: 3

PostPosted: Fri Aug 23, 2019 9:37 am    Post subject: Reply with quote

Thanks very much!

That is exactly what I needed!

regards,

Hans.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Fri Aug 23, 2019 8:17 pm    Post subject: Reply with quote

Why don't you just qrite it in the template?…
That looks like gross misunderstanding of the templating purpose.
Back to top
View user's profile Send private message
hansr
Smarty n00b


Joined: 22 Aug 2019
Posts: 3

PostPosted: Sat Aug 24, 2019 5:18 pm    Post subject: Reply with quote

Not really,

The website has a number of forms that are all build with standard templates.

This one form however is a completely dynamic subscription form for a great number of events with each a different set of inputs and options, governed by a database. Therefore a static template is not an option.

Because all the other forms are made with Smarty templates, I am trying to build this one with Smarty too so I can keep as close to an MVC solution as possible.

regards,

Hans.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Sat Aug 24, 2019 8:08 pm    Post subject: Reply with quote

Then write a form builder that does what you want, or use SmartySecurity module and store form template in the database, editable by user(s).
Resorting to "string:…" template is a least performant route, IMO.
Back to top
View user's profile Send private message
Leedsman
Smarty n00b


Joined: 25 Oct 2019
Posts: 1

PostPosted: Mon Oct 28, 2019 11:41 am    Post subject: Reply with quote

Could a SmartySecurity module do this btter than a form?
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Tue Nov 05, 2019 8:05 pm    Post subject: Reply with quote

They serrve different purposes. (Assuming you did mean form builder I suggested earlier.)
SmartySecurity let you allow your users write Smarty templates AND limit their ability to affect system's stability through controlled execution.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP