Support » Developing with WordPress » Understanding Core Logic:Template Assignment

  • Resolved WhirledPress

    (@whirledpress)


    I am reading through core to understand the logic better and had several questions that are probably easy to answer, but may be useful to other developers as well:

    With regards to template file selection/assignment. Why is this done completely separately from the template tag assignments?

    In class.wp-query.php it appears that the $query_vars and conditional tags are set. Wouldn’t it be more efficient to determine which template file to load at the time that we process the query vars rather than the big (if (is_something && something_template_exists) use template) that happens in template.php?

    Perhaps you could set a query variable that was private (so as not to conflict with the template if passed in the query) allowing us to skip all the steps in template.php?

    NOTE: I am not suggesting this is an error or that this hasn’t been evaluated and the best path is what we have now, I just am asking for the logic to understand it better. I’m, sure this has been evaluated and there are undoubtedly reasons why it’s done the way it is. I just wondered how you came to the decision.

    Thanks in advance for any information.

    P.S. If this is not the correct forum to ask questions of this nature, could someone please point me to the correct forum? I don’t mean to distract or anger anyone, I’m just trying to get better at understanding WP.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    I don’t see how it would be more efficient one way or the other. We shouldn’t decide the template until the conditional tags have all been determined. One tag might logically supersede another, but we can evaluate them independently in any order. If templates were assigned with the tags, we’d need to supersede the template as well. It can be done that way, but then the tag evaluation order becomes finicky and more difficult to maintain. I like it better to set the tags as encountered in whatever order and determine the template through cascading logic later.

    Whether it’s immediately later or some time later wouldn’t make any difference, you’d still end up with that crazy logic cascade. At least this cascade makes template hierarchy fairly evident. To be clear, we are only determining the template in this discussion, not loading it. We could never load templates when tags are determined because they cause output, but we’ve yet to send headers, which have to be done before output.

    As it is, templates are determined just before they are loaded. This fits with the “just in time” philosophy sometimes followed. Whether that’s significant here or not, I don’t know. I’d be interested to learn how the template assignment could be done more efficiently without compromising maintainability.

    Thread Starter WhirledPress

    (@whirledpress)

    Thank you so much. That makes a lof of sense. I appreciate the reply.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Understanding Core Logic:Template Assignment’ is closed to new replies.