Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [templating]

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

1
vote
1answer
32 views

Filter entries with AJAX

How would I sort blog entries displayed using AJAX? What I want to achieve is initially show all posts from a channel (All) but then let my users sort through these posts with a sub navigation using ...
1
vote
1answer
95 views

How to do CSS/JS bundles/minifying in Craft 3

I would like to combine all of my sites JS-files into one bundle - and perhaps also obfuscate it. Same goes for CSS-files. How would I do that in Craft CMS 3?
1
vote
1answer
24 views

Neater way to merge this conditional entry query?

I know there's a better way to do this - eg by merging in the relatedTo parameter if categorySlug is defined rather than defining 2 different queries, but I can't for the life of me figure it out... ...
0
votes
0answers
9 views

Tag list not displaying All Tags

I have this loop, but it's not actually displaying all tags? Is there a reason for this? {% set relatedTags = user.userInterests.all() %} {% if relatedTags|length %} {% for rel in ...
1
vote
3answers
44 views

Paginate Tag Page

I'm looking to paginate my tag page, but unfortuntately it throws a fairly strange error. Remove the pagination -> the page works perfectly? Bit confused, the only thing I think it may be is that it's ...
1
vote
2answers
26 views

Access entry content in _layout.html

I have some content I wish to output in the main parent _layout.html template. Seems like something simple to achieve but can't seem to figure it out. If I call {{ entry.bannerLabel }} etc it throws ...
2
votes
1answer
33 views

How to re-populate form with old values when submitted from a controller?

I have a form in a template which makes a request to the specified action (a controller). The controller decides that there is an issue with the inputs and needs to provide error output for the user. ...
1
vote
1answer
24 views

Craft 2: get default user group from user settings

In Craft 2, I know I can get general config settings. How can I get the current Default User Group (set in Settings > User Settings) for use in my templates?
2
votes
1answer
48 views

Order by Numeric Custom Field Value

I'm trying to order my entries by a numeric custom field named score, some of these values can be 0 but unfortunately, it's not getting ordered at all? {% set users = craft.users.group('influencer')....
1
vote
1answer
14 views

Related Entries to Users

I'm currently doing the following query, it's working nicely on my local environment but on Production it's allowing all users to see all entries which is really strange? I can't see anything wrong ...
1
vote
2answers
13 views

Why is category.getUrl() returning incorrect subdomain?

Forgive me if this is a server configuration or other issue unrelated to craft, but perhaps someone has some insight on what might be causing this, and how to fix it. When using a simple category....
1
vote
1answer
21 views

Replace throwing Unknown Modifier Error

I've tested the regex and seems to work perfectly, but when placing it within Craft it seems to throw the following error: preg_replace(): Unknown modifier '/' {% set ig = user.instagram|raw|...
1
vote
1answer
12 views

Entry Group Empty State

I have entries that are getting grouped, but I've noticed that it will return nothing if there's nothing within a group. I'm looking to see if there's a possibility of showing an empty state to a user?...
1
vote
1answer
12 views

Merging params PostDate limits errors

I'm attempting to merge in postDate restrictions based on the url segment. However I get twig errors with my code. So for a link of domain.com/news/archive/2016 I want to see all entries with a ...
1
vote
1answer
23 views

Offset not working correctly

I have an entry that has a entries field where 9 entries have been added. The first three entries are displayed in one block at the top of the page and this works correctly using .limit(3) However ...
1
vote
1answer
11 views

Show Users who have a related entry

I'm looking to show the users that have an entry relating to the currentUser, it is currently working but is obviously showing duplicates e.g. admin, admin as admin has 2x posts associated. Is there a ...
1
vote
1answer
24 views

AJAX Update Entry (500 Internal Server Error)

I'm trying to update an entry on the front end with a click and without a form. I'm a bit new with AJAX but would love to simply put a new title for the entry that the button relates to. I'm currently ...
1
vote
2answers
31 views

Creating entries loop with nth loops across unordered lists

I'm looking for some help with the most efficient and performant way to generate this loop. | COL 1 | COL 2 | COL 3 | | 1 | 2 | 3 | | 4 | 5 | 6 | | 7 | 8 | 9 | | ...
1
vote
1answer
14 views

Get and display a product's variant fields in twig

I'm working on a product template that can display products of any type. Various product types have varying numbers of variant fields each with their own options as other products. (All of my variant ...
0
votes
0answers
12 views

Injecting filename into all templates?

I found a topic about getting the current filename for templates here: How can I make a template output its own filename? but I am curious, is there some way I can get the server to implement this ...
0
votes
0answers
26 views

Craft Commerce Stripe Not Creating Subscriptions

I have the following code trying to sign up someone to a subscription plan using Stripe Commerce. Unfortunately, no subscriptions are getting created in Stripe Test and no errors are getting given. {%...
0
votes
0answers
18 views

Restricting Access Per User Posts

I'm looking to restrict access to users posts until another user follows for a development site I'm building out, but I can't get my head around how to sort the permissions. Here's the current ...
1
vote
1answer
19 views

Values from fields in templates

I have categories in my cms. How do I gets a list of these value into my templates? Thanks.
2
votes
1answer
12 views

Iterate through all rows of specific page using Freeform?

Documentation (http://docs.solspace.com/craft/freeform/v2/template-objects/page.html#usage-in-templates) says you can iterate through all rows on CURRENT page or entire form. I need all rows/fields ...
1
vote
2answers
47 views

Get Entry by Specific ID

I have a Freeform Email Notification getting sent out where I'm trying to fetch the ID of a specific entry that the Email is associated to. The emails are working, yet the entry that it's returning is ...
1
vote
1answer
46 views

Purge HTML but leave Line Breaks

I'm looking to purge all the html from a text field, but leave the line breaks in there. I currently have the following code, which makes line breaks happen, but unfortunately, people can add html to ...
1
vote
1answer
21 views

Two entries same category

I have two different sections that share the same category group that I want to display both on browser at the same time only if the category is the same. Doing that in Craft CMS is possible? Thank ...
1
vote
1answer
22 views

Get random entries from a section but keep the order of these when splitting the array

So I want to get 9 random entries from a section and I do this like so: {% set artists = craft.entries .section('artists') .artistImage(':notempty:') .with(['artistImage']) .orderBy('RAND()') ...
1
vote
1answer
23 views

How do you get the user id on the front-end?

I'm using Craft Pro to make a website where users have a private area. Users register and when login happens they are redirected to a page in the private area with respective info about that user. ...
1
vote
1answer
22 views

How to get an element query into json (for vue) without extra data?

Lets say I want to get a list of category names and ids and pass them into JSON (for vue.js). This is how I'm currently doing it: {% set sections = craft.categories.group('teamCategory').select(['...
2
votes
2answers
22 views

Searching a subset of fields

I have a section in Craft that has 36 fields, and I want to: set entries = craft.entries.section(sectionName).search(searchCriteria).all() where 'searchCriteria' searches only 6 of the 36 fields. ...
1
vote
1answer
24 views

Extend templates from outside templates directory

I have a setup where I'm using a component library that I have as an npm package. To use these components I need to extend templates that live outside of the /templates directory. So I need to achieve ...
2
votes
1answer
20 views

Maintaining order when getting by entries by ID

I'd like to get a certain set of entries in a specific order, but the element query comes back ordered by the default 'postDate desc' {% set ids = ['4213','3200','4204','4212'] %} {% set ...
1
vote
1answer
38 views

RequirePermission not working

I'm using the requirePermission tag in the templates for my Craft multisite. I only want users who have access to 'edit' that site be able to view it. My code is: {% requirePermission('editSite: (...
1
vote
1answer
31 views

Form Redirecting to Homepage

I'm trying to make a form redirect to the current page, but it's currently redirecting itself to the homepage every time the form submits? I can't see anything wrong with the code itself? <form ...
0
votes
1answer
34 views

Ajax Contact Form not sending with Error 400

Hi I have I'm using Craft CMS 3.1.21.1 with the Contact Form plugin version (2.2.4) and Contact Form Honeypot plugin (1.0.2) along with jquery 3.2.1 on the site. Whenever the form is filled out and I ...
1
vote
1answer
24 views

Entries with different styling

Is it possible to build categories with a list of entries that have different styling, like {% for entry in entries %} Row 1 - Entry 1 - full-wide Row 2 - 3 entries with (1/3 width of each) ...
1
vote
1answer
20 views

String interpolation in Redactor

I have a redactor field whose HTML contents contain links to other parts of the website. How do I render variables located in the HTML content of a Redactor field in Twig? Sample redactor content: &...
1
vote
2answers
115 views

Twig errors on v3.1.19

Running Craft 3.1.19 and have started getting twig error in the control panel. When I click on the utilities link I get this error: Declaration of craft\web\twig\Environment::compileSource(Twig\...
1
vote
1answer
155 views

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` ...
1
vote
1answer
23 views

How to add attributes to links/scripts?

How do I add additional attributes values while registering a CSS/JS file? I want to add a media attribute to one of the CSS links Example code: {% do view.registerCssFile(siteUrl ~ 'css/print.css',...
1
vote
1answer
15 views

Display Relating Entry based on Page Routing

I'm trying to create a submission page at the following URL structure /campaigns/this-is-a-test-creation/submissions As you can see /campaigns/ is the Channel and the /this-is-a-test-creation/ is ...
1
vote
1answer
50 views

Ignoring “The ” and “A ” when sorting entries

I have this code which used to work with 2.x versions: {% set foobars = craft.entries({ section: "foobars"}).order("(CASE WHEN title LIKE 'The %' THEN SUBSTRING(title, 5) WHEN title LIKE 'A %' THEN ...
1
vote
1answer
24 views

Output raw html from if statement and combining strings?

I have the following code: <img{{ block.imageWidth|length ? ' width="' ~ block.imageWidth ~ 'px"' }} /> If imageWidth is specified as 120, it should output: <img width="120px" /> ...
1
vote
1answer
40 views

Looping Related Entries with a Super Table

I need to loop related entries. I am using a SuperTable field with the handle "related" with an entry field with the handle "contentEntry" and two text fields for alternative text and descriptions. ...
1
vote
1answer
24 views

Display all fields without knowing object type?

I was looking for a way to show all fields/properties of a given object, and came across this useful tidbit: How to display all fields belonging to current entry? I'm new to Craft/Twig and didn't ...
2
votes
1answer
25 views

How to query entries written in a specific locale? (Craft 3)

In Craft 2 you used to be able to do something like {% set entries = craft.entries.section('something').locale('de') %} but .locale() has been removed and there's nothing similar in the docs that I ...
1
vote
3answers
56 views

404 – Not Found from _entry.twig templates in subdirectories

Following the Minjingo CraftQuest tutorial, I am getting an error on the front end when I access any routes other than the root/home page. In my template folder, I have a structure that looks like: ...
1
vote
1answer
95 views

How to strip out src=“” value with twig from iframe code

I have have a text field for copy-pasting an iFrame code. <iframe src="https://webpagelink.com/l/3556456/2019-03-06/34576" width="100%" height="500" type="text/html" frameborder="0" ...
1
vote
1answer
24 views

Grouping entries and ordering by section

Im grabbing entries from two sections and displaying them using the group filter. {% set entries = craft.entries().section('extendedEvents, festivalEvents')%} {% set allEvents = entries %} {% set ...