3

I've got a craft field where I have an such as:

Learn more about this great %Job Title% job.

I'm then using Twig Replace to insert the actual entry.jobTitle into the %Job Title% space.

This works great.

But visually, I'd like to highlight the job entry. So I'm wrapping it in a span tag.

Here is an example of the output I want:

<h3>Fantastic opportunity for a <span class="highlight">Head Chef</span></h3>

So at the moment I've got it looking like this, pulling in the jobStatement (The line with %Job Title% somewhere in it):

<h3>{{ jobs.jobStatement|replace({'%Job Title%': "<span class='highlight'>" ~ jobs.jobTitle ~ "</span>" }) }}</h3>

Alas, when the template is rendered, it is rendering the entries as text. How can I insert the HTML span tags around the Job Title area?

Any help much appreciated,

Stephen

5

Try using twig's raw filter.

<h3>{{ jobs.jobStatement|replace({'%Job Title%': "<span class='highlight'>" ~ jobs.jobTitle ~ "</span>" })|raw }}</h3>
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.