Hot answers tagged

20 votes
Accepted

What's the best way to set up a content-manageable 404 page?

I would create a Single with the URI set to "404", and also set its Template to "404". That entry will automatically get loaded if you go to http://example.com/404, and load your 404.html template, so ...
user avatar
19 votes
Accepted

How to write a simple navigation?

My solution is to setup a dedicated "Menu" section and use an entries field type for the links. This allows you to pull together entries from multiple sections into a single menu. My normal setup is ...
user avatar
14 votes

How to write a simple navigation?

I pulled together this brain-dump of 8 different ways of doing navigation. There's probably more. With any method make sure you keep a close eye on the query count and load speed, as some of these ...
user avatar
  • 3,924
14 votes

Password protect a single page

Yes. Use the RequireLogin tag at the top of a page: {% requireLogin %} This tag will ensure that the user is logged in. If they aren’t, they will be redirected to the Login page, and returned to ...
user avatar
12 votes
Accepted

How do I return ALL entries that are singles

There's no such method available for craft.entries, at least it's not documented. But you can use craft.sections to get an array of section models and filter them with a conditional within a loop: {# ...
user avatar
  • 35.8k
9 votes
Accepted

Route breaks Single Entry

Craft automatically includes the entry variable if the slug matches the url: If the URI matches an entry’s or category’s URI, the section’s/category group’s template will get loaded, and the ...
user avatar
  • 8,316
8 votes
Accepted

How do I get the url of single pages?

Craft creates an EntryModel for each Single Section, that allows you to access the URL property you are after. You can get the (one) EntryModel using the Section's ID and the first() method: {% set ...
user avatar
  • 35.8k
8 votes

How to write a simple navigation?

In some cases I use a pre-defined (very simple) nav that I don't need to be driven from the CMS yet I want to share it between the header / footer. In these cases I'll set an array in my base layout ...
user avatar
  • 329
8 votes

Globals versus Singles

The performance aspect is difficult to answer. On every pageload, Craft pulls all your global sets, which can be a performance hit, especially if you have many huge, complex global sets with a lot of ...
user avatar
7 votes

How to write a simple navigation?

If you have more complex menus in the future, you should take a look at the Nav-Tag. . Getting singles: There isn't an easy way to get singles (yet). But you can use the same method which is used ...
user avatar
  • 8,316
7 votes

How to use a Structure including a homepage

You can place your homepage entry in a Structure by setting its slug to __home__. Doing so causes the entry to answer for the / (empty) URI, and it even places the little "home" icon in place of the ...
user avatar
  • 3,400
5 votes
Accepted

How to properly setup single page templates

If I've deciphered what you're asking correctly, I think the solution you need is to set the single to use your about/index template, not the about/_layout-about template.
user avatar
4 votes

How to write a simple navigation?

Another easy way to handle a dynamic menu in Craft is to add a Matrix field to a Global. For example, I have a Global called "Main Menu". That Global has a Matrix field called "Menu Item". I then ...
user avatar
4 votes

How to write a simple navigation?

1) This is not so simple of an answer. Craft itself uses JS to handle the content of indexes, so I'm not sure how they're doing this. Using what's available you would need to build a list of Single ...
user avatar
4 votes
Accepted

How flexible is tying content to a structure?

Structures simply add an extra bit of sorting and querying. You can look for entries in a structure the same way you look for entries in a channel. The difference is that you can also have parents and ...
user avatar
4 votes

Simple navigation with active class?

If you just want to set the active class on static nav then you can just create a conditional using any defining attribute (i.e. title, slug, id, uri-segment, etc). Here is an example using the uri-...
user avatar
4 votes
Accepted

How to use a Structure including a homepage

Updated answer to reflect your added uri requirements. Given your desired uri patterns, I would recommend moving 'subpage-1', 'subpage-2', and 'subpage-3' to the root of your structure which will ...
user avatar
4 votes

Parent/child Single sections

Ignoring the obvious "use a Structure" answer, I suppose you could fake a "hierarchy" by placing a child and parent entry field on each of your Single sections and manually assigning entries as ...
user avatar
  • 66.4k
4 votes
Accepted

Parent/child Single sections

Take a look into Entry Types, I'm pretty sure that's a much better way to handle what you're trying to achieve: https://craftcms.com/features/entry-types So you'd have a Structure section (let's ...
user avatar
  • 23.6k
3 votes

How to use a Structure including a homepage

You don't have to use an extra single section for the homepage, see here: "Add home page to a structure?" Edit: As this question is slightly different to the one I linked to, I will add some more ...
user avatar
  • 35.8k
3 votes
Accepted

content and fields won't show up on new single

I fixed it... I hadn't assigned a field to the section.
user avatar
  • 186
3 votes
Accepted

Loop through fields from 'single'

I think there's a few ways you can do this with twig. You should be able to check whether the category slug exists as an attribute on the entry object: {% for category in craft.categories.group('...
user avatar
  • 4,361
3 votes
Accepted

Single entry with 450 Matrix blocks throwing error on save

Most likely you're bumping into php.ini limitations. I'd bump the values of memory_limit, post_max_size and max_input_vars and see if that helps. They are common culprits when POSTing large amounts ...
user avatar
  • 66.4k
3 votes
Accepted

Change name of Singles

Add a /translations/ folder to your project root and within that folder a /fill-in-locale-here/ folder. Add a file "app.php" to that /translations/fill-in-locale-here/ folder which returns an array of ...
user avatar
  • 157
3 votes

Where does Craft store HTML Templates?

It sounds like you have access to the CP, but not the server. In order to modify the template files (usually stored in the templates directory, next to the public web folder), you'll need SSH or FTP ...
user avatar
2 votes

What's the best way to set up a content-manageable 404 page?

404 redirect: You could set up your single to use 404-not-found (example) as a uri, and add a redirect: {% redirect '/404-not-found' %} to the /404.html file. That way every 404-page gets ...
user avatar
  • 8,316
2 votes

How to write a simple navigation?

This doesn't work for every project, but for brochure style sites I like having all the client-arrangeable pages in one Structure, with toggles on each entry to optionally show in primary or secondary ...
user avatar
2 votes
Accepted

Get content of single by slug

Singles have no need for slugs, which is why we don't expose them in the CP UI for a single. They only have one in the database because they're technically entries, and entries need slugs. But it's ...
user avatar
  • 66.4k
2 votes

Get content of single by slug

I don't think that either the single's uri or the handle is technically considered a slug per se, although in the case of singles craft likely interprets the handle as such. A more appropriate way to ...
user avatar
2 votes

How do I get the url of single pages?

To get an URL to a specific CraftCMS single entry. Look up for the entry unique id in admin panel and then apply in Twig template: Example below: {% set page_cookies_policy = craft.entries.id(10)....
user avatar
  • 99

Only top scored, non community-wiki answers of a minimum length are eligible