Jump to content

JavaScript placeholders


Recommended Posts

So, I'm trying to implement a placeholder system on my forum, with a rather special syntax (I couldn't come up with something else, rather).


Basically, they're supposed to look like this:



{{t12345}} // link to an URL starting with t (for topics)
{{t12345,12345}} // link to an URL starting with t but also include a fragment identifier for the exact post
{{u12345}} // link to an URL starting with u (for users)
{{homepage}} // any string of text can be inserted, I just want to interpret them differently, depending on the string
{{h123}} // link to an URL starting with h (for html pages)


So, I've written a Regex for this and want to replace it with according <a> tags...



var regex = /\b(\{\{((t\d{1,5}|t\d{1,5}\,\d{1,6})|h\d{1,3}|DA|u\d{1,5}\}\}))/g;
html = document.getElementsByTagName("body")[0].innerHTML;
html.replace(regex, '<a href="$1">Generated link</a>');


That should do the basic user stuff, but for the homepage, HTML and topic URLs, I need an appending - to make the code work together with my forum's PHP pages.


So, any ideas how I could change the URL according to the content on the $1 from the regex match?


Thanks in advance...

Link to comment
Share on other sites

Maybe I'm not understanding what you are doing. Why are you using regex to replace the placeholders? Just put those placeholders inside tags (DIV or SPAN) with an ID. Then just reference the ID. Are all of these on the same place in the page? If so, put them all within a parent container.

Edited by Psycho
Link to comment
Share on other sites

Thing is, they're supposed to be dynamic and I want even illiterates to be able to use them without placing them inside divs or spans, so, for example...


"This is Irate from {{homepage}} and recently, {{t12345,12345}} has caught my attention, so I want to thank {{u12345}} for creating this exceptional idea, which I have realized in {{h123}}."


Am I being clear enough? :s

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.