View previous topic :: View next topic |
Author |
Message |
hansr Smarty n00b
Joined: 22 Aug 2019 Posts: 3
|
Posted: Thu Aug 22, 2019 8:03 am Post subject: Insert Smarty variable in dynamic HTML |
|
|
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:
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 |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Fri Aug 23, 2019 7:09 am Post subject: |
|
|
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 |
|
hansr Smarty n00b
Joined: 22 Aug 2019 Posts: 3
|
Posted: Fri Aug 23, 2019 9:37 am Post subject: |
|
|
Thanks very much!
That is exactly what I needed!
regards,
Hans. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri Aug 23, 2019 8:17 pm Post subject: |
|
|
Why don't you just qrite it in the template?…
That looks like gross misunderstanding of the templating purpose. |
|
Back to top |
|
hansr Smarty n00b
Joined: 22 Aug 2019 Posts: 3
|
Posted: Sat Aug 24, 2019 5:18 pm Post subject: |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Sat Aug 24, 2019 8:08 pm Post subject: |
|
|
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 |
|
Leedsman Smarty n00b
Joined: 25 Oct 2019 Posts: 1
|
Posted: Mon Oct 28, 2019 11:41 am Post subject: |
|
|
Could a SmartySecurity module do this btter than a form? |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Tue Nov 05, 2019 8:05 pm Post subject: |
|
|
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 |
|
|