47

As of Craft 2, you should be using the new siteUrl config setting. There are two advantages to setting your site URL using this config setting. First, The value can be set on a per-locale basis, in a way where Craft is actually aware of all locales’ URLs on every request (unlike the CRAFT_SITE_URL constant, where Craft only knows the current locale’s URL). ...


19

Fabien Potencier, the main developer of the Twig templating language answered the question like so: Macros: reusable markup across a lot of templates Includes: part of "pages" that are extracted for readability and reusability The reason for this, as far as I understand, is that you can only use the include tag to render the complete file ...


9

I recently setup a structure which contains (almost) every page of my site. When I set it up, I specified only {slug} as the URL. So far, it's working fantastically! And that's with about 30-40 pages created in the structure (some nested within others).


9

TL;DR: Let the content dictate how you model and architect it. If the site is sufficiently small or sufficiently simple, I think either approach is ok. My team has used both approaches, and it really depends on the Client's needs. An incomplete list of reasons to use separate channels and structures are: Tagging/Categorizing things like Products is ...


8

For your example, you should exclude the fictional towns in the initial query itself rather than filtering them out afterwards: {% set towns = craft.entries.section('towns').townFictional('not 1').relatedTo(counties) %} So that no towns with the Fictional Lightswitch on will be returned from the database at all. You would use the |without filter, if you ...


8

Regardless of the number of elements involved, Craft will return an iterable ElementCriteriaModel whenever you query for content (e.g. via craft.entries, or using relational FieldTypes like Assets, Entries or Categories). This means that even if you know that there'll only be a single element returned (e.g. when you query for a Single section entry, or have ...


7

You basically have two options for creating a "listing" or "archive" view for your Channel or Structure sections. The first option is to create a Single. This is in many cases appropriate, e.g. if you need to add content to the listing view in addition to the actual entry list, such as a visual banner, introductory text etc. Inside the Single section's ...


6

This is how relationships work in Craft at the moment. Each relation equals +1 query. If you don't access your relation on an entry the query isn't executed. So by only fetching title and/or id you don't run any extra relationship queries. Caching is your best option at the moment to make the query count go down. Make use of caching to cache large chunks of ...


6

I'm not familiar with ACF, but if you're looking for blocks-within-blocks, you could use the Neo plugin/fieldType. It allows you to define blocks, and then have nested blocks. It allows for decent management of blocks, too, so that you have children of specific parents. For example: You could have the following blocks/content types: Copy Card Image ...


6

A structure is a section that allows for a 'tree' like layout with hierarchy. A good example of where Structures might be used for instance is the Craft documentation pages, or building a navigation using a section.


6

If you're throwing Exceptions from your plugin, then those will automatically get logged in Craft's log files at craft/storage/runtime/logs with full stack trace information, so there is no need for extra logging there. In you're using Craft::log or PluginHandlePlugin::log statements, and you set LogLevel::Error, or LogLevel::Warning, then those messages ...


6

You could have a single News section that is enabled for each of the locales, and choose which locale each entry should target from their Edit pages. To make it easer on the authors, you can set the default status to Disabled for each of the locales, from the section’s settings. Then when creating a new entry, the authors only have to enable the one locale ...


6

That's the setup we use here. It's ok, but local development runs slowly because the database is off-site - we'll be moving to an internal database server in the new year because of that. Image transforms we just deal with by manually syncing the folders every now and then. I believe Andrew Welch has a script to help manage that - I've not tried it https://...


5

Sections are for completely separate areas of content. They have their own URLs, and are conceptually different. Like blog posts and press releases would be different sections. Your sections could easily be one section with a different set of categories defining web development and general writing. This is entirely up to you. Categories are for separating ...


5

There’s no reason for your controller to return anything – it will never be checked. Many requests call more than one controller action, so it would be pretty presumptuous for Craft to think that it should actually output whatever your controller returns, and end the request. Instead, it’s up to the actual controller to do the outputting, and end the ...


5

Both are essentially the same query, the only thing that differs is the WHERE statement. The ID approach will always be the most efficient, since it uses the primary key index, thus finding the result faster. You could also do the first example the same way you did the second one: {% set entry = craft.entries.section('information').slug('about').first() %}...


5

One improvement I think could be made is to fetch only the ID's of your hotTubs entries at the start of your code. You're only using this to get the related categories and fetching ID's is faster than fetching the actual elements. The relatedTo parameter works perfectly with ID's. So that could speed up things. You can drop the orderBy parameter also as this ...


4

I built a plugin which does exactly this... Ad Wizard. You can put your ads into groups, and add that group to your template like this: {{ craft.adWizard.position('rightSidebar') }} That code will automatically display a random ad from the group (unless it's disabled, expired, or over its maximum allowed impressions). You can also target a single ad ...


4

I would use a lead paragraph field that you could then call into the RSS feed. Or you could add a post summary field. You could then call that whenever you need to, RSS or otherwise.


4

You can simply add it inline to your body tag like so: <body style="background-image: url({{ myGlobal.myAssetsField.first().url }})"> If you want to only use it with selected templates, you'd better use Craft's includeCss tag: {% set bodyCss %} .myBodyClass { background-image: url({{ myGlobal.myAssetsField.first().url }}); } {% ...


4

Matt Wilcox alluded to it in his original comment, but something like Craft-Scripts will really help out with this workflow. You can read more here: Database & Asset Syncing Between Environments in Craft CMS


4

At the risk of offering a "link answer", the Setting up a New Craft CMS 3 Project has a section on DEPLOYING CRAFT CMS that should be useful to you. I've never heard of Rocketeer, but popular ways to handle deployments are via buddy.works, Laravel Forge and the like. We talk a lot about this on the Website Deployment without Tears episode of devMode.fm


4

The job of naming something is sometimes the most difficult part of a project! This is pretty subjective, but even though it seems like those three fields would share the same settings and requirements (as mentioned by @Paul Werheul), if it was me I would choose field names like clubName, teamName, and playerName. This way the field names explicitly state ...


3

If you are using a Structure to manage your site hierarchy, and the news index page naturally falls in that hierarchy, then yes, this can work well. Make an entry type for the index page, and in your template (which is the same for all the entry types), {% include ['_page/'~entry.type, '_page/_default'] %} (So if you haven't defined a template for this ...


3

Yes, it is possible. Pass the entry type handle to a segment and access that segment using the craft.request getSegment() method. Use this segment variable with the craft.entries .type() method to fetch only the entries of the given type. The example below assumes your entry type handle is in segment 2. {% set entries = craft.entries.section('pages').type(...


3

A different News Channel for each location: For example: News Location 1 with Entry URL Format location-1/news/{slug} News Location 2 with Entry URL Format location-2/news/{slug}


3

You build this in a couple different ways but the simplest would be to setup ads as as channel with an asset for the add, url etc. In the template you could set the ad [the entry] to appear randomly by using shuffle().


3

I would use a matrix field with multiple types.


3

I suppose it depends on what the code is going to be doing. If it's standard "business logic" code related to your plugin, then it would make more sense to add it to your plugin's services, which is where we recommend that type of logic goes. There, it handles the interactions with the database and returns the appropriate models back to your plugin's ...


2

You could use a mulit-environment config for your "locations" (if my guessing is right and you want different Base URLs). Both "locations" (= environments) get access to the same content. Then you can access your site on: http://www.location-1.com http://www.location-2.com ...


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