Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2020-08-06 05:58:15

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,007
Website GitHub Mastodon Twitter

'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

#2 2020-08-06 06:30:49

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,595
GitHub Twitter

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

#3 2020-08-06 10:54:59

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: 'default' attribute for variables

Normally, default is global and should work for all tags. Have you tried it?

Offline

#4 2020-08-06 11:08:56

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,007
Website GitHub Mastodon Twitter

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

#5 2020-08-06 11:12:11

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: 'default' attribute for variables

colak wrote #325194:

I’ll add it to the docs later.

Nobody reads it anyway :-)

Offline

#6 2020-08-06 11:28:24

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,007
Website GitHub Mastodon Twitter

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

#7 2020-08-06 11:51:35

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,250
Website GitHub

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:

  1. Remove any common and global atts from the page that are not handled specifically or differently by that tag.
  2. Add the include line that reads the atts-common.html after the dedicated attributes list. Add att_name="" for any you wish to include from the common set. You can set the default value inside the double quotes.
  3. Below that, add the include line that reads the atts-global.html. Add att_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, the class 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

#8 2020-08-07 03:05:19

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,595
GitHub Twitter

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

#9 2020-08-07 14:08:13

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

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

#10 2020-08-07 16:02:58

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,595
GitHub Twitter

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

#11 2020-08-07 17:40:51

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,007
Website GitHub Mastodon Twitter

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

Board footer

Powered by FluxBB