Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pass an argument to a customer form, sos it will output a value?
I want to make a custom form where I set a URL and a text string, and the form includes the URL and text string when it outputs its code. Is there a way to do this?
I have this code:
<a class="cta-link" href="https://app.mural.co/embed/442ee02f-a9d7-4370-a513-c1c04618aa60">
<div class="call-to-action">
<div>
<h3>Goal mapping canvas template (Mural)</h3>
</div>
<div><img alt src="/h/download.png">Use Mural template</div>
</div><!-- END .call-to-action --></a>
I would like to invoke it as a custom form and pass the URL and H3 contents as variables.
Something like:
<txp:output_form form="form-name" url="url" h3="h3 text" />
Is that a thing?
Offline
Re: Pass an argument to a customer form, sos it will output a value?
agovella wrote #343463:
Is that a thing?
Yes, it absolutely is. See Custom short-tags and shortcodes in the docs. There are some examples in the docs too.
You can use txp:output_form if you want, but you can also make it a tag of its own. For example, if you call your form cta, you would invoke the tag like this, with :: two colons to differentiate them from regular tags:
<txp::cta url="https://app.mural.co/embed/442ee02f-a9d7-4370-a513-c1c04618aa60" h3="Goal mapping canvas template (Mural)" />
and your form would look like this:
<a class="cta-link" href="<txp:yield name="url" />">
<div class="call-to-action">
<txp:if_yield name="h3">
<div>
<txp:yield name="h3" wraptag="h3" />
</div>
</txp:if_yield>
<div><img alt src="/h/download.png">Use Mural template</div>
</div><!-- END .call-to-action -->
</a>
(you’ll probably want to handle the text around the download icon differently, but you get the picture)
If you’re writing short tags for other people to use, you may want to build in some defence mechanisms for when attributes are forgotten. You can see a simple use of txp:if_yield in the example. Alternatively, you can also supply a default for txp:yield if the attribute is not supplied but needed.
TXP Builders – finely-crafted code, design and txp
Offline