I'm wanting to add support for a sort of template language in the database content for our content providers.
We came up with this as a good syntax: {% link URL as NAME [with KEY=VALUE [KEY=VALUE] [...]] %} [ and ] aren't required, I'm just indicating the optional elements. Our idea is we'd rather the teams use this than try to hard code links in the content themselves. And if our programs migrate to other servers or environments (which is typical), we want all linking to route through a single function so we can change them. This also covers external links so we can add things like class=external to add little icon indicators or whatever else. I was thinking this made sense for a inclusion tag since there is an HTML snippet, but since it inherits the context and we're not simply replacing context variables with template variables, this didn't make sense. So I started coding it as a filter since that passes in the content. And also doesn't require "evaluating" the database content using the template libraries but rather manipulates the content directly. I'm not quite done yet but I do have the parsing and substitution working (see doc test below). But I'm curious of general thoughts on this. Is there an easier way? A bad idea in general? I gave a few tries at using the template libraries but didn't see an easy way to do it so I wrote my own parsing of this. If I could integrate with the template libraries and make sort of a hybrid filter that uses template tag syntax that might be best, no? Just now I thought that we could possibly hack up markdown to do this but I like the ease of the tokens and how they are similar to the Django syntax. Versus something like [URL NAME](URL). We can also make the syntax very English like, eg: {% jump to #anchor as "Click to jump" %}. >>> link.link_to("""{% link URL as NAME %}""") '<a href="URL">NAME</a>' >>> link.link_to("""String before {% link URL as NAME %} and string after.""") 'String before <a href="URL">NAME</a> and string after.' >>> link.link_to("""This is a {% link http://google.com/ as "link to google" %}.""") 'This is a <a href="http://google.com/" class="external" target="_blank">link to google</a>.' >>> link.link_to("""This is a {% link myfile.pdf as "PDF File" %}.""") 'This is a <a href="myfile.pdf" class="pdf">PDF File</a>.' >>> link.link_to("""This is a {% link files/myfile.pdf as "PDF File with subdirectory" %}.""") 'This is a <a href="files/myfile.pdf" class="pdf">PDF File with subdirectory</a>.' >>> link.link_to("""This is a {% link 20000 as "Random page" with class=internal %} with extra attribute.""") 'This is a <a href="/page/20000/" class="internal">Random page</a> with extra attribute.' >>> link.link_to("""This is a {% link 20000 as "Random page" with class=internal id=internal1 %} with attributes.""") 'This is a <a href="/page/20000/" class="internal" id="internal1">Random page</a> with attributes.' --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---