Developer654079525's avatar

Link storage

If a CMS stores raw HTML, and some anchor links, or their parts (not many but a few of them) might change in the future, what is the preferred approach to store such links? Use some made up syntax/templating like {:something1}, {:something2} and then regex replace these in the future? Currently I keep the hard coded full URLs and replace parts where they change in the future.

1 like
4 replies
vincent15000's avatar
Level 63

You can effectively save all links in the database and inside the texts, you can call a link like {:link:} and replace with the link.

That means if you need to update some links, you don't need to update the texts, but only the links. Anyway you will need to update something.

But I think that it's quite better to update the texts.

1 like
Developer654079525's avatar

Appreciate it. Is there a preferred syntax, like the one you mentioned, or can it be any sufficiently unique string? I am interested as to why you used the trailing colon symbol.

1 like
vincent15000's avatar

You can use any symbols you want, just be careful it's not a pattern used as a standard text.

I already used this : [[link]]. And then I have a script to search for [[ and ]] and I replace with what I need.

1 like
martinbean's avatar

@developer654079525 It really depends on how that raw HTML is being authored in the first place.

Ideally, yes, you want to remove any hard-coded references to dynamic content. If a user is linking to a page controlled by the CMS, then it’s probably better to store some sort of identifier rather than the URI at that time. You will then need to decide what you do with links to pages that are then deleted entirely, though.

2 likes

Please or to participate in this conversation.