Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
'default' attribute for variables
Would it be too difficult to add an optional default
attribute for variables similar to that used in the yield
tag?
I know that this is a bad example
<txp:variable name="checkcf" value='<txp:custom_field name="cf" />' />
<txp:if_variable name="checkcf" value="">
There is no value
<txp:else />
<txp:variable name="checkcf" />
</txp:if_variable>
which we can make shorter if a default
attribute is added
<txp:variable name="checkcf" value='<txp:custom_field name="cf" />' />
<txp:variable name="checkcf" default="There is no value" />
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: 'default' attribute for variables
+1
Alright, Yiannis.
Exactly the same thing I wanted to suggest: a default value for <txp:variable />
could be easier in many cases!
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
Re: 'default' attribute for variables
Normally, default
is global and should work for all tags. Have you tried it?
Offline
Re: 'default' attribute for variables
etc wrote #325192:
Normally,
default
is global and should work for all tags. Have you tried it?
I just checked it. It does work! I’ll add it to the docs later.
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Offline
Re: 'default' attribute for variables
etc wrote #325195:
Nobody reads it anyway :-)
Yep, that page is pretty hidden. I will be adding it to the tag docs:)
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: 'default' attribute for variables
colak wrote #325197:
Yep, that page is pretty hidden. I will be adding it to the tag docs:)
If you’re in docs mode, take a look at the section_list page on GitHub.
If you edit that page, note how the common and global atts are brought into the page via an include:
{% include atts-common.html break="" breakby="" %}
{% include atts-global.html class="tag name or unset" %}
Basically, we want that on all tag doc pages. We need to:
- Remove any common and global atts from the page that are not handled specifically or differently by that tag.
- Add the
include
line that reads the atts-common.html after the dedicated attributes list. Addatt_name=""
for any you wish to include from the common set. You can set the default value inside the double quotes. - Below that, add the
include
line that reads the atts-global.html. Addatt_name="special instructions for this att"
for any text you wish to override inside the attribute’s string. So as you can see above for the section_list tag, theclass
attribute is treated differently in this tag because it’s not just unset by default, as normal.
Does that make sense?
If you come across any tags that need to omit globals (because they’re handled in a special manner) then I’ll need to refactor the atts-global.html to work in a similar way to atts-common.html so you can omit them. Right now it’s not possible to omit any globals using that include. Sorry, that’s rubbish. Ignore it.
Sorting out the tag docs is on my list to do, but any help in this regard from anyone would be massively appreciated. Thank you.
Last edited by Bloke (2020-08-06 17:00:25)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: 'default' attribute for variables
Oops. My fault.
I was thinking instead about custom fields: the ability to assign a default value if a field is blank (or, for the next TXP version, Devs don’t forget to offer the choice to set a default value to custom_fields
)
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
Re: 'default' attribute for variables
Pat64 wrote #325211:
I was thinking instead about custom fields: the ability to assign a default value if a field is blank (or, for the next TXP version, Devs don’t forget to offer the choice to set a default value to
custom_fields
)
Yep, it is already in custom-fields branch.
Offline
Re: 'default' attribute for variables
Yeah!
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
Re: 'default' attribute for variables
Although I can think of other more verbose methods, I was also thinking that a default for txp:image
might be handy to make 404s easier to handle.
<txp:image id="yy" default="##" />
<txp:images category="yyy" default="##" />
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline