Questions tagged [templating]

Front-end Twig templates that can Craftily render markup, scripts, and styles.

See Craft's Templates Documentation for more.

1705 questions
19
votes
5 answers

Create line breaks from text field

I'm looking for a way to output line break from a text field. I'm aware of the "Allow line breaks" option and I have set that to true. I've then entered text with multiple new lines. However, when this text gets output in the template, there are no…
bravokiloecho
  • 1,583
  • 4
  • 17
  • 22
15
votes
3 answers

Twig syntax highlighting in PHPStorm?

Does anyone know of a way to instruct PHPStorm to treat Craft templates as Twig files, without globally assigning all .html files to be interpreted as Twig? Since Craft templates don't use the .twig extension, PHPStorm thinks they're HTML. On that…
Garrett
  • 417
  • 3
  • 10
13
votes
1 answer

How can I output the Field Name in my template?

I've created a plain text-field and added this field into a section. I then created an entry and filled it with content. I know I can output the content of the field in my template with {{ entry.field_handle }}, but is it also possible to display…
RhealPoirier
  • 297
  • 1
  • 10
11
votes
2 answers

Templates with .twig extension

Does anyone know how to make Craft by default use .twig extensions. It helps IDEs better understand Twig blocks. I have tried .twig and .html.twig but it doesn't appear to work by default. I don't want to set up special configs for every template.
Cristian
  • 111
  • 1
  • 3
8
votes
1 answer

Is it possible to view 'Expired' entrys on the front end?

I have a site with 10000 events which need to expire once they have happened, the main reason for this is to keep things tidy in the CP. We need users to view events that they have completed after they have expired. Is there an easy way to render…
Sam Hibberd
  • 729
  • 3
  • 13
8
votes
2 answers

Can I apply an image transformation to an arbitrary image (non-Assets field)?

Curious if I'm able to use the resizer on a random, sourced image, not coming from a field anywhere. So I would just be passing a string to the path of the image.
Tim Kelty
  • 3,081
  • 1
  • 18
  • 29
8
votes
9 answers

Check if current page is the homepage

I'm trying to run a check within my _layout.html' to remove the navigation bar if the user is on the homepage. I've tried with the following code below, but browsing to a page which is theindex.html` of a Channel breaks the code with the following…
JMKelley
  • 1,384
  • 10
  • 27
8
votes
1 answer

Multiple conditions in an if statement?

Is it not possible to define multiple conditions in an if statement? {% if foo == 'x' || foo == 'y' %} I tried this and got an error: Unexpected token "punctuation" of value "|" ("name" expected)
Roi Agneta
  • 1,463
  • 2
  • 13
  • 21
8
votes
5 answers

Twig "is defined" always returning true

I am trying to code defensively and check whether a field exists before accessing it: {% if e.someField is defined %} {{e.someField}} {% endif %} And I get a CException Craft\EntryModel and its behaviors do not have a method or closure named…
Marion Newlevant
  • 12,047
  • 22
  • 55
8
votes
2 answers

How do I set mime-types for Craft templates?

For example, if I'd like to serve a file as application/json or application/rss+xml I see in the RSS Feed documentation that it mentions saving a file with .rss will auto-detect and serve the correct mime-type. However, how is this detected? Is…
Kara
  • 183
  • 1
  • 5
8
votes
2 answers

Include CSS file inline rather than as a link

I use a pre-processor to generate my CSS. I would like to include the resulting file inline, rather than as a link. Is there a way of doing this via the twig tags in Craft? I know I could move the CSS file to the templates folder, so that I could…
frontendbeast
  • 181
  • 1
  • 1
  • 4
8
votes
2 answers

How do I output an entry author's data

I have a blog. I want to output an entry author's first and last name. What is a good method to accomplish this?
blairrorani
  • 413
  • 3
  • 11
7
votes
2 answers

What's the best way to increment a number of a class or id?

I have the following code which works fine. I'm just wondering if there is a more simple way of incrementing the id number? {% set counter = '1' %} {% for block in entry.news %} {% if block.type == "bodyBlock" %} {{ block.body }} {% elseif…
julzmon
  • 941
  • 2
  • 9
  • 19
7
votes
2 answers

How do I stop my relative links to stylesheets breaking?

When I navigate to [home]/news/2014/poster my relative links to stylesheets break. I am using: How do I stop these links breaking in this scenario?
blairrorani
  • 413
  • 3
  • 11
7
votes
1 answer

Where can I edit the "Service Unavailable" page/template?

Sorry if this is an obvious thing - can't seem to find an answer in the docs. Where can I edit the system offline message? "service unavailable"
erwinheiser
  • 850
  • 7
  • 15
1
2 3
18 19