Skip to main content

Questions tagged [templating]

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

Filter by
Sorted by
Tagged with
1 vote
2 answers
374 views

Replace asterisk (*) with my own HTML in twig-templates

I'm working on a Craft CMS website and I need help with formatting the H1 tag. I would like to be able to easily outline some parts of the title, like in the example below. Ideally by adding an ...
J1989's user avatar
  • 67
3 votes
1 answer
1k views

Get entry associated with current uri

If I am visiting /recipes/spaghetti which corresponds to an entry in a recipes entry type and the recipes/entry template, is there a way to directly get the current entry's data from within the ...
Augustine Calvino's user avatar
0 votes
0 answers
354 views

Passing variables, and reading them, to Module template

I'm trying to pass an array to a module's twig template (on the front end). I have tried many solutions I've seen here, but I'm not able to read the passed variables inside the twig template. In my ...
mauricio's user avatar
  • 187
2 votes
2 answers
2k views

Unable to find the template

I know this question has been asked multiple times. I have read all the post on this topic, and craft's docs. But still, I haven't figure out what I'm doing wrong. I would really appreciate a hand ...
mauricio's user avatar
  • 187
4 votes
3 answers
2k views

Get array of titles instead of whole collection of entries' attributes

I know that to get the entries I can do: craft.entries.all() but instead of getting the whole collection of entries, I would like to get an array of titles from those entries (or any other field). ...
Paloma Martinez's user avatar
1 vote
2 answers
98 views

OrderBy section when selecting multiple sections in entries query

When getting pages from multiple sections like so: {% set aboutNavigation = craft.entries .section(['about', 'newsIndex']) .all() %} How can I set order that the sections appear? So I want ...
Terry Upton's user avatar
  • 1,894
1 vote
1 answer
43 views

Output Matrix field within Channel

Very new to craft and hence sorry if this is very basic. I have created a service channel which contains some matrix fields. One for a list and one for button. My approach here may be wrong and hence ...
Grant Smith's user avatar
0 votes
1 answer
127 views

Improve performance and element queries when used multiple times

So I am building a mega menu and a separate set of templates for mobile. Both use the same set of element queries, which query two larger sections for pages and hierarchy. I am seeing quite slow load ...
Terry Upton's user avatar
  • 1,894
1 vote
1 answer
764 views

Blog pages returning HTTP 404 – Not Found – yii\web\NotFoundHttpException Template not found: blog/_entry

I’ve followed Craft’s instructions to set up the blog: https://craftcms.com/docs/getting-started-tutorial/configure/section.html When I published my first article, it returned a 404 error – see here: ...
scottbabolka's user avatar
1 vote
1 answer
150 views

How to get rules of conditional fields values on front-end, using Reasons or another solution?

I'm building a front-end form, where I'm displaying on front-end my fields following their layout within the CP: {% set section = craft.app.sections.getSectionByHandle('handle') %} {% set ...
Romain P.'s user avatar
  • 1,852
1 vote
1 answer
325 views

Template URL/path alias

Is there any way to use an environment variable in the URL and template path settings for sections? We are prototyping a site with a temporary skin running alongside our front-end build but would ...
Cole Henley's user avatar
  • 1,741
0 votes
1 answer
51 views

How to get field widths when using getFieldLayout()?

I'm trying to show all my Channel's fields on front end, as they are shown on the CP: {% set section = craft.app.sections.getSectionByHandle('handle') %} {% set fieldLayout = section.getEntryTypes[0]....
Romain P.'s user avatar
  • 1,852
1 vote
1 answer
257 views

Loading JavaScript on Template Load

I'm working on a kiosk-type plugin which will cycle through all news entries, beginning upon template (or page) load. It needs to load a JavaScript ajax script for this on page/template load. Would ...
buck1112's user avatar
  • 400
2 votes
1 answer
44 views

Sorting Categories/Entries by # of relations dynamically

does anyone know if there's a way to display a type of "most popular categories" list? It's not exactly my use-case, but it's very similar Essentially, I want to be able to have users search ...
Kevin Amézaga's user avatar
1 vote
1 answer
284 views

Navigation Menu Options - drop downs and sticky?

I'm new to Craft CMS. It is possible to create a navigation menu with drop down menu items and a sticky menu bar on the desktop view please? How/where do I do this please? (Using Craft 2.7.10) ...
Kate Burgess's user avatar
1 vote
1 answer
33 views

What's the best strategy for products that are sold?

I wonder what's best practice for products that are sold? My strategy is to add a lightswitch "sold" and don't display sold products on the website and in the sitemap.xml, in the hopes that ...
outline4's user avatar
  • 595
1 vote
1 answer
689 views

Regular Expression replace not working within Twig Template

I'm attempting to capture 4 attributes of an Attributes of an tag and injecting inline styles to the style attribute. Craft CMS and Twig templates are being used to generate HTML emails here, hence ...
Christopher DuCharme's user avatar
1 vote
1 answer
482 views

How can I pass a variable to Freeform's formatting template so that it's available to Twig?

I want to be able to toggle the display of a form's Title on or off, without having to resort to using a mostly-identical copy of the formatting template. Freeform formatting template: {% if ...
Sandwich's user avatar
  • 636
1 vote
1 answer
68 views

Showing and hiding details (price, sale price, sku etc)when product variant is selected on details page

I currently have price, sku and variant title swapping when clicking between variants on a products details page. This works with AlpineJS and looks something this. https://codepen.io/amasci/pen/...
Terry Upton's user avatar
  • 1,894
-1 votes
1 answer
665 views

Contact Form - Not sending emails

I am getting test emails but not contact form email? {% macro errorList(errors) %} {% if errors %} {{ ul(errors, {class: 'errors'}) }} {% endif %} {% endmacro %} {% set message = ...
DTS's user avatar
  • 23
1 vote
2 answers
809 views

Merging classes in Twig based on component and context

Whats the best way to approach this in twig? So I have a component that is used in multiple places, so within this component I set some default classes like so: {% set navSidebarClasses = { heading: ...
Terry Upton's user avatar
  • 1,894
1 vote
1 answer
23 views

Creating a channel (or entries) using a similar channel

I am currently trying to make a channel called "classmates" similar to a channel that is called "News". I have this working beautifully, but I am not sure how to set a different ...
craft newbie's user avatar
1 vote
1 answer
34 views

Twig Template spits out jibberish when trying to access user-defined fields

I have an Entry called Groups (I'm wondering if this might be some sort of reserved word issue) and, with Twig, I can bring out the base fields of id and title with no issue but when I try to pull ...
Tom Holloway's user avatar
1 vote
1 answer
43 views

Decrease heading level if entry is descendant in Redactor

I am currently building a doc system with multiple levels. I have build individual entries, but I'd like to parse the whole documentation in one page. Currently, I'm doing it like this: {% set pages = ...
katsele's user avatar
  • 33
1 vote
1 answer
572 views

Split string with multiple delimiters

Hi what is the best was to split a paragraph into sentences please? I can use: {{ content|split('.') }} but what if a sentence in the paragraph ends with a question mark or exclamation mark instead? ...
cannon303's user avatar
  • 309
1 vote
1 answer
58 views

in array not matching

I am probably doing something daft here, but tried multiple things to no resolution. I trying to find if a value is in an array but my test case doesn't match. {% if entry.applicationStatus == '...
mmc501's user avatar
  • 1,789
1 vote
1 answer
275 views

Debugging Craft CMS templates on Visual Studio Code

Is there a way to debug templates used in craft cms on visual studio code? I tried doing it but I just get this error: "${workspaceFolder}' can not be resolved. Please open a folder." Any ...
Steven Zhang's user avatar
1 vote
3 answers
456 views

CSS file not being read by other templates

So I am making a new craft cms website, I have my page entries linked to the template pages/_entry.html, which works fine. I then made another type of pages called news, linked to the template news/...
Steven Zhang's user avatar
0 votes
0 answers
171 views

Internal Server Error after upgrading from craftcms 2 to 3

I just upgraded from Craft 2 to 3.6.14 (latest). I was able to successfully to the upgrade. I am able to get into the admin and was even able to install the feed-me plugin. I ported over all the files ...
Karthik N G's user avatar
0 votes
0 answers
189 views

Variable "entry" does not exist - error on homepage single entry

Relatively new to CraftCMS and getting Twig error "Variable "entry" does not exist" on my home page. Noticed another post said to leave URI blank which should fix but didn't. Just ...
DieselHashtag's user avatar
1 vote
1 answer
71 views

Use same handle for different fields on different entry types

I've got two entry types: blog and job. Each has a category field but different category groups: blogCategories and jobCategories. I would like to write a Twig include to accept either a blog or a job ...
Tamlyn's user avatar
  • 183
1 vote
1 answer
50 views

Get related variants from entry and then show products for related variants and then loop only the variants that are related in commerce

Struggling with this one. If anyone can help me...? I have a section of entries called Vehicles. In this I have a related Variants field type. This has many different variants that related to each ...
Terry Upton's user avatar
  • 1,894
1 vote
2 answers
703 views

Checking if a value is in an array of IDS - using a filter?

Is there an easier way to achieve this? Perhaps using a |filter function? {% set variantIds = [] %} {% for variant in product.variants %} {% set variantId = variant.id %} {% set variantIds = ...
Terry Upton's user avatar
  • 1,894
1 vote
1 answer
296 views

Search for assets containing a custom field

How can I search for assets containing a custom field? The field on the asset is called lang. When I use this code no assets are found. {% set folderId = craft.app.request.getQueryParam('folderId') %} ...
Guido Neele's user avatar
2 votes
4 answers
331 views

TWIG dataUrl function for resized images

Craft provides the very nice TWIG function dataUrl(pathToImg) to inline images in e-mails. E.g. <img src="{{ dataUrl('@webroot/assets/img/logo.svg')" /> will base64 encode the image ...
Matthias Redl-Mann's user avatar
1 vote
1 answer
752 views

How can I make make the class of an entry link "active" if entry is the current url?

I'm currently using the below jQuery but it's buggy as it relies on looking for 'similar' URL and not the exact URL. Is there a way it can be done just using Twig? {% set mainNavigation = craft....
DieselHashtag's user avatar
1 vote
1 answer
103 views

Displaying Craft templates in external apps

I'm working on a site that is running Craft v2 and also has an installation of Simple Machines Forum (SMF). This has been fine using the approach outlined in this answer, i.e. $craft = include '/craft/...
Tyssen's user avatar
  • 653
2 votes
1 answer
1k views

Showing and playing video's in Twig templates

I want to be able to upload and play videos on my Craft CMS website. I created a volume and field to hold these videos. So far so good, but whenever I want to output the video in a video tag I'm not ...
J1989's user avatar
  • 67
4 votes
1 answer
730 views

Interpret TWIG's {% js %} as <script> in PHPStorm

Does anyone know how to get PHPStorm interpret {% js %} as <script> for correct syntax highlighting in PHPStorm? Background: I'am always doing this: {% js at endBody %} {% if false %}<...
Matthias Redl-Mann's user avatar
1 vote
0 answers
57 views

Craft 3 entry.author.getPhoto() is coming up null on template, but the author has a photo uploaded in the user > details section, any ideas why?

The site is utilizing a Servd bucket to store all assets. The backend shows a photo successfully uploaded to the user > details section, but does not provide a url in the entry.author.getPhoto(), ...
user11767's user avatar
1 vote
1 answer
36 views

Order of {% set %} tags changing output unexpectedly

I have a content builder matrix that I'm looping through to build my page. That code works with no problems. {% set content = entry.pageBuilder.all() %} {% for block in content %} {% include "...
artmem's user avatar
  • 1,022
1 vote
1 answer
366 views

Load currentUser using Sprig with Blitz

I'm having an issue with Sprig + Blitz Caching. I'm trying to load a user image if currentUser exists, though I'm having an issue with the caching. Sprig is loading in the unregistered user photo when ...
JMKelley's user avatar
  • 1,416
1 vote
1 answer
109 views

Output Channel entries on another page with a matrix block

I know im doing something small wrong but I cant see what at this point. I have a channel called 'testimonialEntries' and I want to randomly output one of these entries on seperate pages. I cant ...
Spheriri's user avatar
  • 132
1 vote
1 answer
258 views

Maps plugin not rendering

I'm currently trying to implement a Google maps via Maps plugin: https://github.com/ethercreative/simplemap I'm following documentation entirely, using PRO version of the plugin. In the plugin ...
Dario Ljubojević's user avatar
1 vote
2 answers
1k views

Load Entry via Ajax

I'm simply looking to onClick load an entries content via Ajax. Thought I see a lot of mixed answers here on SO, some referring to Element API, Creating a Plugin and GraphQL. Is there a simple way to ...
JMKelley's user avatar
  • 1,416
1 vote
1 answer
122 views

Open Entry in a Modal

Unsure how to go about doing this. I'm looking to open a related entry in a modal on the same page. In an area, I have a list of houses. On click, I would like the user to open a modal and load the ...
JMKelley's user avatar
  • 1,416
2 votes
1 answer
2k views

Accessing array/object attributes in Twig

There are three methods for that: object.attribute object['attribute'] attr(object, 'attribute') How are these different from each other?
Piotr Pogorzelski's user avatar
1 vote
1 answer
765 views

Output javascript inside twig variable

I am using the Enupal Stripe Payments plugin to pass line items to Stripe. The line items get passed in an array. I want to use a javascript cart to hold the items in local storage, reformat that and ...
triplethreat23's user avatar
1 vote
1 answer
32 views

Display Count of Entries posted today

I'm trying to display a notification badge on how many new entries were posted today only. But I cannot get the following to work. {% set timeAgo = now|dateModify('today') %} {% set ...
JMKelley's user avatar
  • 1,416
1 vote
1 answer
138 views

Google Maps plugin - How to trigger an info window

I'm migrating Smart Map over to the Google Maps plugin, and I want to open a popup on button click. But it seems there is no JS method available to open an info window. Here's how it was done in Smart ...
Taher Kathiriya's user avatar

1 2
3
4 5
35