Partial support for Vae
  • This is useful when you'd like use the same HTML block(s) in several different locations in your template.

    Syntax

    To register a partial simply wrap your code in a v:partial tag:

    <v:partial id="product">
    <v:img path="image" />

    <v:if path="price">
    <div class="price"><v:text path="price" /></div>
    </v:if>

    <div class="name" title="<v:text path="name" />"><v:text path="name" /></div>
    </v:partial>


    ... and then to use that partial in any context (single document or collection):

    <div class="featured product">
    <v:partial id="product" path="/products[price > 0]" />
    </div>

    <ul class="products">
    <li><v:partial id="product" path="/products" /></li>
    </ul>


    Note: The partial output tag takes the same parameters as v:collection.

    Code (put this in __vae.php):

    function partial($attributes, $tag, $context, $callback) {
    global $partials;

    $id = $attributes['id'];

    if (count($tag['tags']) > 0) {
    if (!is_array($partials)) {
    $partials = array();
    }

    $partials[$id] = $tag;
    } else {
    if (array_key_exists('path', $attributes)) {
    $context = vae($attributes['path']);
    }

    return vae_render_tags($partials[$id], $context);
    }
    }

    vae_register_tag('partial', array(
    'handler' => 'partial',
    'params' => 'collection',
    'required' => array('id')
    ));

  • 1 Answer sorted by
  • Very cool to see a working example of building a custom vae tag.

    Can't the same thing be accomplished though using templates?


    in partial.html:
    <v:img path="image" />

    <v:if path="price">
    <div class="price"><v:text path="price" /></div>
    </v:if>

    <div class="name" title="<v:text path="name" />"><v:text path="name" /></div>


    ... and then to create the context context (section or collection:


    <div class="featured product">
    <section path="/products[price > 0]">
    <v:template filename="/includes/partial.html"></v:template>
    </v:section>
    </div>

    <ul class="products">
    <v:collection path="/products">
    <li>
    <v:template filename="/includes/partial.html"></v:template>
    </li>
    </v:collection>
    </ul>



    It would be great to see if either has a speed advantage to the other.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Apply for Membership

In this Discussion