1

Is there a way to find out if an entry is enabled for a particular site?

I know there's the enabledForSite property, but it doesn't look like it accepts any arguments. Ideally I'd like to do something like {% if entry.enabledForSite(2) %} or {% if entry.enabledForSite('siteHandle') %}.

Thanks!

1

Based on the anyStatus and site query parameters, it should work like this:

{% set entries = craft.entries()
    .site('foo')
    .enabledForSite(true)
    .all() %}
  • Thanks @ChristopherDosin - however, this would allow me get all entries that are enabled for a particular site, rather than check if a particular entry is enabled for a particular site. I suppose I could do something like {% set count = craft.entries().id(entry.id).site('foo').enabledForSite(true).count() %} but it's not ideal – Pete H Oct 9 at 15:31
  • Why is this not ideal? This would be the query. Get your specific entry, from the specific site and check if it's enabled or not. What's wrong with the query? :) – Christopher Dosin Oct 9 at 15:33
  • There's nothing wrong with the query. It's a lovely query. It just doesn't do what I need. Your query returns all entries that are enabled for the specified site. I need to check if a specific entry is enable for a specific site. The query I posted would work, but I don't love having to do a whole new query for something that should ideally be a property of the entry object I already have. – Pete H Oct 9 at 15:42
  • Unfortunately there's not such a parameter. enabledForSite accepts just true or false. I would just go with your query. – Christopher Dosin Oct 9 at 15:45
  • OK thanks, appreciate your help :) – Pete H Oct 9 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.