Stack Exchange Network

Stack Exchange network consists of 174 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.

0
votes
0answers
5 views

hashing form fields to prevent tampering

I have a front end form for entry creation. I have a few options I don't want tampered with. The docs for |hash say "Prefixes the given string with a keyed-hash message authentication code (HMAC), for ...
1
vote
0answers
11 views

Entries sorted by title have some entries not alphabetical

I have the following code to return some grants, but whilst most of the entries are coming back alphabetically ordered, after the last "Z" entry, there are a few more entries also alphabetically ...
1
vote
1answer
20 views

where command sql query not working

My problem is that I can't update the specific $userId. have the values I've selected. I also get an error: Call to a member function where() on integer I just started to learn Craft. It can be ...
1
vote
2answers
18 views

Nested category navigation

I am trying to achieve the following markup for my categories navigation: <h3><a href="categoryurl">Top Category One</a></h3> <ul> <li><a href="categoryurl"&...
1
vote
1answer
19 views

Mobile page support

Is there any good practice to how to serve mobile pages differently from Twig? What I would like to achieve is the following, right now we have pages like: http://myawsomecraftpage.com/stories/aaa-...
1
vote
1answer
18 views

Connection between twig template and website content

I am new to Craft and I am basically inheriting a site that I now need to maintain. I am a developer, not really a web designer, and my current task is to change the layout on the homepage. ...
1
vote
2answers
18 views

Sending Error Message to Template With No Logged In User - Craft 2

I'm working at getting error messages sent from my plugin to my template (on the front end), when there is no session (no logged in user). The plugin is for LDAP authentication. Edit: For ...
0
votes
1answer
14 views

RelatedTo “and” and arrays

I have something I can not get my head around. This works as expected: .relatedTo(['and',{targetElement:22},{targetElement:33}]) But when I am building an array to use as relation criteria like so: ...
0
votes
0answers
13 views

Get to get all users with active Commerce 2 subscription

How do I get all the users with an active subscription in Commerce 2? I want to be able to filter entries by subscribed users.
1
vote
1answer
54 views

Eager loading on entry not reducing queries

Using this snippet returns me 38 queries on my homepage without the Eager Beaver plugin. {% do craft.app.elements.eagerLoadElements( className(entry), [entry], ['headerImage', 'image1', '...
1
vote
1answer
16 views

CKEditor Null Value

I'm using CKEditor as one of my fields, I'm trying to detect if there is any content within them, unfortunately it's still appearing even using the below code (and the field is actually empty). {% if ...
1
vote
1answer
29 views

How can I list Entry Types of a single Section?

The following outputs all sections and their entry types, but I'm struggling to work out how I output only the entry types from the "blog" section. {% for section in craft.app.sections.allSections() %...
0
votes
1answer
10 views

Counting section handle in TWIG with weighted search plugin

I am using the weighted search plugin to inplement a search functionality in my site. It works as it should but I am looking for a way to tell how much results were found of each type. Where type for ...
0
votes
1answer
13 views

field from category not available via craft.categories

my categories have a custom field called titleTag for SEO as well as a number of other fields. When I render them at their URI (/categories/cat1) I can output those fields easily with {{category....
1
vote
2answers
31 views

How to wrap a matrix blocktype occurrence loop inside a ul?

I made a template including a matrix field. I want to wrap all occurrences of a certain block type into a <ul> element. How can I do this? My current code: {% for block in entry.matrixField....
1
vote
3answers
22 views

Keeping order of blocks like in backend

Fairly new user here. I am kinda confused how to template. I want to rearrange the order of blocks in my backend and show them in the right order in the front. Here is how i am currently writing a ...
1
vote
1answer
22 views

How to use the default HTML email template when sending an email from a plugin?

On /admin/settings/email, when the HTML Email Template field is set to a valid template, all system messages are sent using it. They inject the content of the messages inside the {% block main %}{{...
1
vote
3answers
135 views

Template not found 404

Having a strange issue - devMode is set to false, if I go to /404, I get the custom 404 page, which is great. If I go to /something1234567890 (which is definitely not an entry's URL) I get the ...
1
vote
1answer
41 views

How to Render a State Abbreviation in Craft CMS?

Folks, Is there a way to render a state abbreviation in a front end template on Craft CMS? Currently, I have a plain text field that has the full text of a state and I would like to render the ...
1
vote
3answers
45 views

Craft templates in sub directory

We want to add a little more structure to our templates directory by adding folders to group templates files. For example: templates --_macros --_views --_layouts In general this works fine but we ...
1
vote
1answer
19 views

Check if the first block in a Matrix field matches one of an array of types

I need to check if the first block in a Matrix field matches one of an array of types. Here's a simplified version of my code: {% if entry.newsArticleContent.one().type in ['fullWidthImage', '...
2
votes
1answer
19 views

Build array from nodes from RSS where keys contain colons

Probably pure twig: I am building an array from nodes taken from a RSS-feed where one of the keys contains a colon which of course breaks everything. Like so: Node in feed: <media:thumbnail url=...
1
vote
2answers
73 views

A-Z Separate Pages

I've built a page listing all entries by Character 0-9/A-Z. But unfortunately it's extremely slow loading due to the amount of entries the site has. I'm wondering if I can break out the letters into ...
1
vote
0answers
22 views

How to print all possible options of a dropdown field inside of a Matrix field?

I'm asking this outside an entry context. My starting point is {% set field = craft.app.fields.getFieldByHandle('matrixFieldHandle') %} When I print the data of the field, I find nothing ...
1
vote
0answers
10 views

Recursive relations – how to build list properly?

I started building a list of recursive relations: We're in a project, we want to check interviews related to that project, see which persons participated in those related interviews, and then build ...
0
votes
1answer
17 views

How to get one entry's related stuff in Vuejs component

For example, in a vuejs component, i send a ajax request to get an article. And in this article, there is a relation field called relatedTopics. How can I get this article's relatedTopics with ...
1
vote
2answers
30 views

Caching question

How does the Craft CMS cache work? I want to show a certain message if the server date is between x and y. Can I do this by using an Twig if/else statement or is this cached? My code is like this: {...
1
vote
0answers
31 views

JsonLD & Schema

What is the best way to use Json-LD schema in the templates for Craft 3? I would like to dynamically load parts of the info. I know about the SEOmatic plugin but looking for a way to do it on my own.
1
vote
1answer
28 views

How do I remove the index.php from all URLS in Craft 2 CMS?

I am very new to Craft and have only been working with it for a few hours. However, I am stuck with something I can't seem to figure out. I understand the basics of templates, of which I have an ...
1
vote
1answer
17 views

Is there a way to return the number of columns in a table?

Is there a way to return the number of columns in a table? I tried {{ entry.tableHandle | length }} but this seems to return the number of rows rather than columns. I've got a site with a couple of ...
1
vote
0answers
20 views

Craft CMS 3 create custom field in plugin with two fields returning two values

I need to get two text fields under the same custom form and have it return two different values to be stored in the database. Right now with what I have, it's storing the same variable for both, ...
1
vote
1answer
21 views

Commerce 1 find if Discount object is valid based on start/end dates (Twig)

In Twig, I want to find out if a discount is valid based on start/end date. startDate and endDate don't seem to exist and I can't inspect the discount object by using the json_encode filter (returns {...
1
vote
1answer
13 views

Payment Method and Discount elements query by ID in Twig

In Craft 2, is it possible to query a specific element by ID in Twig? They aren't mentioned in the docs. I was trying things like these but without success: {{ craft.commerce.paymentMethods.id(1)....
1
vote
1answer
15 views

CP: Title from relation?

I have the following 1:n relation between two sections: Source Element: Interview Target Element: Persons In the CP (only there) I need to be able to identify Interviews by the name of the ...
2
votes
1answer
22 views

Alphabetical index for a list of entries

I would like to build an alphabetical list of craft entries, but group them by the initials of one field of each entry. Thus, getting some kind of alphabetical index, like A Apples Ananas B Beer ...
1
vote
0answers
18 views

Categories and Sub Categories

Good morning and thank you in advance. Very to new Craft and Twig so I am not sure if I am coding this correctly but need some help. I have a forms center that has 5 main categories (Members, ...
1
vote
1answer
32 views

Where does Craft store the field definitions?

I would like to add field and section definitions to versioning. Or at least, have them backed up constantly. I haven't been able to find out yet how craft handles this. I'd say it's in the database, ...
1
vote
3answers
51 views

Templating basics: extend, include or use?

I'm making first steps with Twig in Craft. Ok, it's a Twig question. But maybe you can give me the best practice for Craft? I'm used to create templates Top-Down, like having a master.html template ...
1
vote
2answers
48 views

How to create single lines from a plain text field with line breaks

Building on this question here: Create line breaks from text field What approach would be best for breaking a multi line plain text field into multiple single lines to be used as: <span>{{ ...
2
votes
2answers
72 views

How do I hide tags in a category that have no entries?

Entries can have one of two categories and one tag. (People = entries | program = categories | year = tag) On the pages I'd like to display entries related to the category and grouped by tag. ...
1
vote
1answer
30 views

Access pages data with fewer queries by creating an object in Twig

I have the goal of querying the database once for page info, and then using it to display information on select pages site wide. For example, I want to link the the contact page with using a url slug ...
2
votes
1answer
31 views

Nesting block tags doesnt work

I have pagination twig component that needs to inject seo links into of page (rel canonical). I tried to use {% block %} twig tag for this, but problem is that pagination component is already ...
1
vote
1answer
26 views

How can I get the type of a field using Twig?

I would like to loop through all the fields of a field layout tab form the current entry. This is working fine to get the field name and value: {% for fieldLayoutField in entry.getFieldLayout()....
1
vote
1answer
37 views

How do I differentiate between entries after merging an array?

I'm trying to plot entries from two different Solspace Calendars and an Entries section on one map, and use different markers for all types. Alll of the events are related to the current Entry through ...
1
vote
1answer
27 views

How to get the previous or next two entries

I have an entry which needs to display the previous two entries, and the next two. I see in the docs there's a nextSiblingOf method. That does nothing in a channel, and in a structure it will only ...
1
vote
0answers
18 views

Commerce: reading Stripe object in Craft Transaction model

I'm looking to add the credit card last four digits to my customer's frontend order history. Stripe is the gateway. The Stripe transaction object doesn't seem to be available in the Craft ...
1
vote
1answer
17 views

Get the location and id of asset volumne

Is it possible to get the location (/media) and id (1) of an asset volume from within a Craft template?
1
vote
1answer
51 views

Template loads via jQuery .load(), but no {% js %} tags are included

Inside of a modal window I'm loading a form template via jQuery .load. For reasons I don't know, the {% js %} tags that need to come with the form template are not being loaded, even though the {% js %...
1
vote
1answer
124 views

How to render a template from within a module?

I'm currently developing a module that contains a custom field and I'd like to create a template to be used in the getInputHtml method. I try using the Craft::$app->view->renderTemplate method ...
0
votes
2answers
29 views

How to display data in field type with dropdown multi select checkbox?

I'm able to get data using API but when I use checkboxField then it only display the blank checkbox without value. In Model, if($result){ if (isset($result->error)) die($result->...