Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2018-06-12 09:15:40

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 6,618
Website

Post your Short-Tags

Short-tags were introduced on txp v4.7 and although I was initially worried about the learning curve, it proved to be really easy. I just thought that it would be good if people posted some of their short-tags here for some cross-fertilisation of ideas.


Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | NeMe @ github

Offline

#2 2018-06-12 09:21:16

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 6,618
Website

Re: Post your Short-Tags

Short-tag for vimeo which includes a GDPR cookie acceptance.

<txp:if_yield name="setcookie"><txp:oui_cookie name="accept_vimeo_cookies" duration="+1 year" values="yes" /></txp:if_yield>
<txp:hide>This sets the cookie and it is required just once/article</txp:hide>
<txp:oui_if_cookie name="accept_vimeo_cookies">
<div class="embed-container"<txp:if_yield name="id"> id="<txp:yield name="id" />"</txp:if_yield>>
<iframe src="https://player.vimeo.com/video/<txp:yield name="video" />?title=0&amp;byline=0&amp;portrait=0" allowfullscreen></iframe>
</div>
<txp:else />
<div class="vimeoeucookies noprint">
<p class="centre">This video, <txp:if_yield name="txt">presenting <txp:yield name="txt" /></txp:if_yield> is hosted by Vimeo on <a rel="external" href="https://vimeo.com/<txp:yield name="video" />">vimeo.com/<txp:yield name="video" /></a>. By viewing it here, you accept Vimeo's <a rel="external" href="https://vimeo.com/privacy">privacy policy</a>.</p><p class="red centre"><a rel="nofollow" href="?accept_vimeo_cookies=yes<txp:if_yield name="id">#<txp:yield name="id" /></txp:if_yield>">View</a></p>
</div>
</txp:oui_if_cookie>

And the tag

<txp::vimeo id="vid" video="xxx" txt="yyy" setcookie="" />

Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | NeMe @ github

Offline

#3 2018-06-12 09:45:55

NicolasGraph
Plugin Author
From: France
Registered: 2008-07-24
Posts: 810
Website

Re: Post your Short-Tags

colak wrote #312522:

Short-tag for vimeo which includes a GDPR cookie acceptance. […]

Thanks colak, I guess that providing an example of this form used a custom shortag would make the use of attributes easy to understand.

…and you could also use core short tags, right?

<if::yield name="setcookie">
    <oui::cookie name="accept_vimeo_cookies" duration="+1 year" values="yes" />
…

Last edited by NicolasGraph (2018-06-12 09:52:08)


Nicolas
Follow me on Twitter and GitHub!
Multiple edits are usually to correct my frenglish…

Offline

#4 2018-06-12 09:56:35

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 6,618
Website

Re: Post your Short-Tags

Hi Nicolas,

I have to admit that I am yet to start using core short-code but from your example, it does indeed save some typing.


Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | NeMe @ github

Offline

#5 2018-06-12 11:21:02

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 6,618
Website

Re: Post your Short-Tags

Short-tag for Vimeo OR YouTube videos with GDPR cookie acceptance

<txp:if_yield name="setcookie"><oui::cookie name='accept_<txp:yield name="provider" />_cookies' duration="+1 year" values="yes" /></txp:if_yield>
<txp:hide>This sets the cookie and it is required just once/provider/article</txp:hide>

<oui::if_cookie name='accept_<txp:yield name="provider" />_cookies'>
	<div class="embed-container"<txp:if_yield name="id"> id="<txp:yield name="id" />"</txp:if_yield>>
		<txp:if_yield name="provider" value="vimeo">
			<iframe src="https://player.vimeo.com/video/<txp:yield name="video" />?title=0&amp;byline=0&amp;portrait=0" allowfullscreen></iframe>
		</txp:if_yield>
		<txp:if_yield name="provider" value="youtube">
			<iframe src="//www.youtube.com/embed/<txp:yield name="video" />?rel=0" frameborder="0" allowfullscreen></iframe>
		</txp:if_yield>
	</div>
<txp:else />
	<div class="nocookies noprint">
		<txp:if_yield name="provider" value="vimeo">
			<p class="centre">This video, <txp:yield name="txt" wraptag="presenting <+>" /> is hosted by Vimeo on <a rel="external" href="https://vimeo.com/<txp:yield name="video" />">vimeo.com/<txp:yield name="video" /></a></txp:if_yield>. By viewing it here, you accept Vimeo's <a rel="external" href="https://vimeo.com/privacy">privacy policy</a>.</p><p class="red centre"><a rel="nofollow" href="?accept_vimeo_cookies=yes<txp:if_yield name="id">#<txp:yield name="id" /></txp:if_yield>">View</a></p>
		</txp:if_yield>
		<txp:if_yield name="provider" value="youtube">
			<p class="centre">This video, <txp:yield name="txt" wraptag="presenting <+>" /> is hosted by Youtube on <a rel="external" href="https://www.youtube.com/watch?v=<txp:yield name="video" />">youtube.com/watch?v=<txp:yield name="video" /></a></txp:if_yield>. By viewing it here, you accept Youtube's <a rel="external" href="https://www.youtube.com/intl/en-GB/yt/about/policies/">privacy policy</a>.</p><p class="red centre"><a rel="nofollow" href="?accept_youtube_cookies=yes<txp:if_yield name="id">#<txp:yield name="id" /></txp:if_yield>">View</a></p>
		</txp:if_yield>
	</div>
</oui::if_cookie>

Sample short-tag

<txp::video id="vid" provider="vimeo" video="xxx" txt="yyy" setcookie="" />

> Edit: Thanks, Nicolas and Oleg. Changed the code.

Last edited by colak (2018-06-12 16:21:30)


Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | NeMe @ github

Offline

#6 2018-06-12 12:47:27

etc
Developer
Registered: 2010-11-11
Posts: 2,675
Website

Re: Post your Short-Tags

Another possible shortcut:

<txp:yield name="txt" wraptag="presenting <+>" />

instead of

<txp:if_yield name="txt">presenting <txp:yield name="txt" /></txp:if_yield>

etc_[ query | search | pagination | date | tree | cache ]

Offline

#7 2018-06-12 15:19:19

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 6,618
Website

Re: Post your Short-Tags

Links with rel attribute

<a href="<txp:yield name="url" />"<txp:if_yield name="rel"> rel="<txp:yield name="rel" /></txp:if_yield>"><txp:if_yield name="txt"><txp:yield name="txt" /><txp:else /><txp:yield name="url" /></txp:if_yield></a>

Sample tag

<txp::link url="https://textpattern.com/" rel="external" txt="Love Textpattern" />

Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | NeMe @ github

Offline

#8 2018-06-16 18:53:43

Destry
Moderator
From: Haut-Rhin
Registered: 2004-08-04
Posts: 3,754
Website

Re: Post your Short-Tags

I think all of those <txp:if_yield /> tags can be written as:

  • <if::yield />
  • <if::yield> ... </if::yield>

Saves you 3 characters each time.

Just depends how far you care to venture into the woods before it gets too abstract and scary.

Offline

Board footer

Powered by FluxBB