/**
 * Include a content slot in your template.
 * 
 * This replaces get_sympal_content_slot() and is intended to be easier
 * to use. This also taps into the app.yml config for its options
 * 
 * @param string $name The name of the slot
 * @param array  $options An array of options for this slot
 * 
 * Available options include
 *  * content         An sfSympalContent instance to render the slot for
 *  * type            The rendering type to use for this slot (e.g. Markdown)
 *  * default_value   A default value to give this slot the first time it's created
 *  * edit_mode       How to edit this slot (popup (default), inline)
 */
function _get_sympal_content_slot($name, $options = array())
{
    if (isset($options['content'])) {
        $content = $options['content'];
        unset($options['content']);
    } else {
        $content = sfSympalContext::getInstance()->getCurrentContent();
    }
    // mark this content record as having content slots
    $content->setEditableSlotsExistOnPage(true);
    // merge the default config for this slot into the given config
    $slotOptions = sfSympalConfig::get($content->Type->slug, 'content_slots', array());
    if (isset($slotOptions[$name])) {
        $options = array_merge($slotOptions[$name], $options);
    }
    // retrieve the slot
    if ($name instanceof sfSympalContentSlot) {
        $slot = $name;
        $name = $name->getName();
    } else {
        $slot = $content->getOrCreateSlot($name, $options);
        unset($options['default_value']);
    }
    $slot->setContentRenderedFor($content);
    /**
     * Either render the raw value or the editor for the slot
     */
    if (sfSympalContext::getInstance()->shouldLoadFrontendEditor()) {
        use_helper('SympalContentSlotEditor');
        return get_sympal_content_slot_editor($content, $slot, $options);
    } else {
        return $slot->render();
    }
}
Exemplo n.º 2
0
/**
 * Get Sympal content slot value
 *
 * @param Content $content  The Content instance
 * @param string $name The name of the slot
 * @param string $type The type of slot
 * @param string $renderFunction The function/callable used to render the value of slots which are columns
 * @param array  $options Array of options for this slot
 * @return void
 */
function get_sympal_content_slot($content, $name, $type = null, $renderFunction = null, $options = array())
{
    if ($type === null) {
        $type = 'Text';
    }
    $slot = null;
    if ($name instanceof sfSympalContentSlot) {
        $slot = $name;
        $name = $name->getName();
    } else {
        $slot = $content->getOrCreateSlot($name, $type, $renderFunction, $options);
    }
    $slot->setContentRenderedFor($content);
    if (sfSympalContext::getInstance()->shouldLoadFrontendEditor()) {
        use_helper('SympalContentSlotEditor');
        return get_sympal_content_slot_editor($content, $slot, $options);
    } else {
        return $slot->render();
    }
}
Exemplo n.º 3
0
foreach ($sf_sympal_content->getSlots() as $slot) {
    ?>
        <?php 
    if (!$slot->is_column) {
        ?>
          <fieldset id="sf_fieldset_<?php 
        echo $slot->getName();
        ?>
">
            <h2 class="sf_fieldset_h2"><?php 
        echo $slot;
        ?>
</h2>
            <div class="sf_admin_form_row">
              <?php 
        echo get_sympal_content_slot_editor($sf_sympal_content, $slot);
        ?>
            </div>
          </fieldset>
        <?php 
    }
    ?>
      <?php 
}
?>

      <?php 
echo button_to('Go back to Editing Content', $sf_sympal_content->getEditRoute());
?>
    </div>
  </div>