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

2
  • Looks like this might be a duplicate of this question. Commented Jun 12, 2015 at 17:53
  • Many thanks Douglas, indeed it is, many thanks.
    – Pathfinder
    Commented Jun 12, 2015 at 18:24

1 Answer 1

5

Try using twig's raw filter.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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