Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango: DRY Internal links in TextFields
    text
    copied!<p>I have a site with a bunch of 'Projects' which often refer to each other in their descriptions (stored in a TextField). Rather than hard-coding the links between projects in their descriptions, I'd like to keep things DRY by referring to them using some sort of token, for example, in the description field:</p> <pre><code>Blabla text describing this project, this project was inspired by {{ project "ProjectB"}} and lead to the development of {{ project "ProjectC" }}. </code></pre> <p>Which is then processed and turned in to:</p> <pre><code>Blabla text describing this project, this project was inspired by &lt;a href="/projects/ProjectB"&gt;ProjectB&lt;/a&gt; and lead to the development of &lt;a href="/projects/ProjectC"&gt;ProjectC&lt;/a&gt;. </code></pre> <p>To be clear: the description is free text which can contain none to many references to other items as hyperlinks at various points in the text. In a CMS this effect is usually achieved through some way to link to items by node/object ID - so that if the link changes, the reference can still be followed.</p> <p>I've considered:</p> <ul> <li>Evaluating the text field as a Template and using the 'url' templatetag in descriptions. Seems like the easiest solution but that templatetag isn't particularly friendly for content editors and evaluating each description through the entire Template renderer seems a bit cumbersome.</li> <li>Implementing a templatetag which just re-implements a basic faux-templating system to just parse out a nice simple tag just for this purpose.</li> <li>Extending the TextField to pre-process the description before it's saved to the database.</li> </ul> <p>Has anyone done anything similar? What would you suggest?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload