Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2012-04-18 11:20:47
- alice_c
- Plugin Author
- From: Karlsruhe, Germany
- Registered: 2004-07-03
- Posts: 33
bep_if_link_url
My Customer maintains his links in the footer by the textpattern links. Now he realised, that some of the medicals in collaboration don’t have a website. So i quickly hacked a plugin bep_if_link_url:
function bep_if_link_url($atts, $thing) { global $thislink; assert_link(); $url = trim($thislink['url']); $condition = (!empty($url))? true : false; return parse(EvalElse($thing, $condition)); }
Perhaps it helps someone.
Offline
#2 2012-04-18 11:42:51
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,315
Re: bep_if_link_url
Even if I don’t have a use right now for a plugin, I always like to know what it does so I can have it in the backyard drawers of my brain if I need to resort to something new. But alas: no PHP knowledge. What exactly does your plugin do, I mean why would I enter links for non-existent websites? (Something around that is what I understand it’s been written for.)
BTW weren’t you the one to hack the core for searchable custom fields back in TXP’s youth?
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Re: bep_if_link_url
uli wrote:
why would I enter links for non-existent websites?
I’ve used it as a cheap “directory of stuff” in the past, e.g. affiliate organisations, all filed under a particular category. Sometimes the organisation has a URL associated with it, sometimes not. In these situations, the plugin is handy (thanks alice_c).
btw, rather than use a plugin I’ve again cheated and used variables in the past:
<txp:variable name="has_link"><txp:link_url /></txp:variable>
...
<txp:if_variable name="has_link" value=""><txp:else /><txp:variable name="has_link" /></txp:if_variable>
It’s not as pretty as a dedicated conditional or plugin though.
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
#4 2012-04-18 12:23:48
- gomedia
- Plugin Author
- Registered: 2008-06-01
- Posts: 1,373
Re: bep_if_link_url
adi_link does a similar thing:
<txp:adi_link quiet="1" />
The quiet
bit tells it not to moan if there’s no URL. I’ve used it in the past for exactly the same reason, i.e. there’s a list of “things” – some with, some without associated links.
Offline
Re: bep_if_link_url
And here’s one I’m using… related to Stef’s
<txp:linklist category="some_link_category" limit="99" sort="linksort" break="li" wraptag="ul">
<txp:variable name="haslink" value='<txp:link_url />' />
<txp:if_variable name="haslink" value="">
<txp:link_name escape="" />
<txp:else />
<a class="ext" href="<txp:link_url />" rel="external"><txp:link_name escape="html" /></a>
</txp:if_variable>
</txp:linklist>
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
#6 2012-04-18 16:37:08
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,315
Re: bep_if_link_url
Thanks to you all, for answers and examples!
A rest lack of knowledge still remains, though. txp:link_list
doesn’t hickup either when there’s no URL filled in. But it displays the wrong link. Would adi_link or bep_if_link_url respectively remove the anchor tag from the list entry or remove the list entry from the page altogether?
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Re: bep_if_link_url
uli wrote:
Thanks to you all, for answers and examples!
A rest lack of knowledge still remains, though.txp:link_list
doesn’t hickup either when there’s no URL filled in. But it displays the wrong link. Would adi_link or bep_if_link_url respectively remove the anchor tag from the list entry or remove the list entry from the page altogether?
Hi Uli, my example above deals with just that issue without using any plugins. The variable checks if there is a link and if there isn’t it just displays the unlinked title of the entry in the linklist. You can see it in action here
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
#8 2012-04-18 18:36:21
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,315
Re: bep_if_link_url
colak wrote:
my example above deals with just that issue without using any plugins.
Yes, exactly. Your example opened my eyes to what might be imaginable in a link list scenario. The difference between your code and Stef’s (who displays nothing in case of empty URL entries, thus seems to use the backend as a close-at-hand note pad) was what made me aware of the different concepts people might have. That’s what make’s me curious, information I find in such moments is often useful later on on a completely different issue.
But my question was actually meant to find out how bep_if_link_url handles empty URL fields (train my PHP muscles, learn reading code).
Hence and in general, here are some more questions:
Can it be used as a container? Yup, that’s how conditionals work (The line with true : false
seems to be an alternative for if/else.) Aha 1.
Which tag would it replace? None, see above. Aha 2 .
Which of TXPs attributes work?
Replacement for that one: I saw $atts
in the code above. Does that mean the tag has attributes?
Last edited by uli (2012-04-18 18:55:09)
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
#9 2012-04-19 05:47:52
- gomedia
- Plugin Author
- Registered: 2008-06-01
- Posts: 1,373
Re: bep_if_link_url
uli wrote:
Would adi_link or bep_if_link_url respectively remove the anchor tag from the list entry or remove the list entry from the page altogether?
adi_link outputs nothing if there’s no URL – is that what you mean?
Offline
Re: bep_if_link_url
All those ‘solutions’ look like a valid upcoming roaring feature request for TXP core to allow more cheap databasae usage with ‘links’ than just for linklists :)
Last edited by merz1 (2012-04-19 11:54:53)
Get all online mentions of Textpattern via OPML subscription: TXP Info Sources: Textpattern RSS feeds as dynamic OPML
Offline
#11 2012-04-19 19:30:25
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,315
Re: bep_if_link_url
gomedia wrote:
adi_link outputs nothing if there’s no URL – is that what you mean?
Yes. I tried to get my head around it on the plugin’s page at greatoceanmedia but found it not definite how it behaves.
Thanks anyway.
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Pages: 1