Jump to content

DRY URLs


alan
 Share

Recommended Posts

Hi PWers,

Have you any good ideas about how a DRY (don't repeat yourself) store of URLs could be built for subsequent use within copy? The aim being that should a URL need to be changed it could be edited in the one DRY-location and all instances of it would therefore remain correct.

My idea so far is to have a utility section (not for display) such as

/utils/drys/

with a URL per page

/utils/drys/my-first-dry-link

/utils/drys/another-dry-link

each URL-page would use a template with two fields, the Title for the default copy the link would use and another field to hold the URL. Then to use the link when editing content in TinyMCE one would need to switch to HTML view and insert some PHP+PW code to refer to the link {is this even possible?}.

In a perfect world I would love to be able to swipe text in TinyMCE and the pop-up list of link options include something like "The URL field from this [drop-down menu] page" and what was inserted was a PHP+PW snippet that ensured that in future when the source URL is edited each use of this link will use the new URL.

Cheers to anyone with any comments :) -Alan

Link to comment
Share on other sites

Hi Alan, look at this post from Ryan for 2.3. features. I can also remember Ryan saying something about using links in Tinymce fiels and the like that they where going to resolve the page id or something like that.

- edit - found it

Your idea, to me, doesn't seem that 'DRY'?

Link to comment
Share on other sites

@SiNNuT Thanks for the links I hadn't found those, off to go read, but not before I smile a lot at your delightful pun ;)

Your idea, to me, doesn't seem that 'DRY'?

@Soma Thanks for the link, off to go read...

Link to comment
Share on other sites

OK, having read up those links this DRYness looks exciting, but I don't think it will address my (this) scenario, I should have made it clearer I was thinking of links to external sites:

In a perfect world I would love to be able to swipe text in TinyMCE and the pop-up list of link options include something like "The URL field from this [drop-down menu] page" and what was inserted was a PHP+PW snippet that ensured that in future when the source URL is edited each use of this link will use the new URL.
see update

But v.interested by this 2.3 feature for it's own sake, thanks for pointing it out.

UPDATE: Actually that quoted example is bad and not clear. Sorry. I'm looking for a way to centrally store refs to external sites and then use them in textareas as elegantly as possible and as/when an external link moves I change my central reference to it and all uses of it in the site use the new edited version henceforth.

Edited by alan
Link to comment
Share on other sites

If I understand correctly, perhaps you could store your links as pages. Your 'link' template would have a 'title' and URL field called 'href'. You'd store these pages under /links/ or wherever it makes sense in your site. The 'link' template file code would just be a redirect:

<?php $session->redirect($page->href); 

When you link to these resources in TinyMCE (or elsewhere) you'd link to the /links/some-site-link/ page(s). That would abstract away the actual link to be something that you could change in 1 place and expect that any links to it will get redirected to the right place.

  • Like 1
Link to comment
Share on other sites

Brilliant! :D Of course so simple that simple-me missed it! ;) Thanks Ryan, this is exactly what I need, I got part-way there with realizing I'd want to store my links as pages but I didn't think deeper. Thanks! :D

Link to comment
Share on other sites

SiNNuT Ryan's suggestion does work, I have it running. The only question I have with it and I am not sure it is an issue or if it is if I care, is SEO, whether Google bot reading the 'wrong' (an internal) link rather than an external one with the chosen link test will affect anything. It's an outgoing link not an incoming one so that's good at least (less important I think).

Question alan: how will you know that an external link has changed?

I won't. Not especially. It's more a case of wanting to know that no matter how large a site gets as/when I notice a URL ref needs changing I can change it once and all places where I used it as a link to go to an external place will automatically be corrected.

Link to comment
Share on other sites

SiNNuT Ryan's suggestion does work, I have it running. The only question I have with it and I am not sure it is an issue or if it is if I care, is SEO, whether Google bot reading the 'wrong' (an internal) link rather than an external one with the chosen link test will affect anything. It's an outgoing link not an incoming one so that's good at least (less important I think).

If it matters, I guess it won't be too hard to implementa module which will substitute internal links to external ones. But then you have to remember to clear your cache (if you use it) every time the link page updates.

Link to comment
Share on other sites

But then you have to remember to clear your cache (if you use it) every time the link page updates.

This can be made automatic in the cache options.

Link to comment
Share on other sites

Also consider to write a script that checks all textfields (tinymce textareas) where link could be inserted, to check links and or modify them as needed in one click. Either use simple_html_dom.php class or using some regex.

Other thing I would consider is adding such links using a tag {url:somekeytext} and replace them with a script before the output. This could also be maintained using a "page" with all the links in a repeater with tag and url that will be used for the replacements. Some module hook could maybe even add them to tinymce or its field description for reference.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...