Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Literally displaying the code of a form
I need to build a ‘Pattern Library’ to help in the management of a large 4.7.3 site.
I’m looking to rationalise my Forms in TXP so that staff can make better use of the ‘Override Form’ feature; a section on the site which acts as a visual library of all the various forms (and their associated code).
The ‘associated code’ bit is where I’m stuck.
How do you ‘inline code’ the contents of a form?
eg. calling on plainlinks.txp
would output
<txp:linkdesctitle rel="external" />
Thanks!
Last edited by giz (2019-05-12 21:09:42)
Offline
Re: Literally displaying the code of a form
Interesting question.
There’s likely a better way, but presumably you could leverage textpattern’s safe_field
function inside txp:php
to retrieve the contents of the form code field from the database. If you want to pass the form name to it from outside the txp:php block, you could set that in advance as a variable, and then use that in your php code, e.g.:
<txp:variable name="form_name" value="my_form" />
<txp:php>
global $variable;
echo safe_field(
'form',
'txp_form',
"name = '".doSlash($variable['form_name'])."' AND skin = 'your_theme_name'"
);
</txp:php>
(replacing your_theme_name
with the theme you are using)
It’s likely you might want to iterate over a list of predefined form names. For that you could use rah_repeat or smd_each to populate the variable.
However, is it really the txp tag code you want to show your users or rather the html widget it produces?
If the latter, see what happens if you use the regular txp:output_form
tag inside pre
and/or code
html tags. With a bit of luck, you should get the html code rendered in a code block…
TXP Builders – finely-crafted code, design and txp
Offline
Re: Literally displaying the code of a form
There is no preset way to output forms content, due to privacy restrictions (forms can contain <txp:password_protect />
and other sensible information). However, you can
- enable
fetch_form()
function for use in<txp:evaluate />
via advanced prefs; - call
<txp:evaluate query='fetch_form("my_form")' escape wraptag="pre" />
.
If needed, my_form
parameter can be passed via <txp:variable />
or <txp:yield />
.
Offline
Re: Literally displaying the code of a form
Thanks Jakob & Oleg.
Offline