Hello team,
I have a lot of trouble to use the primer and reference guides to program custom Cornerstone elements.
Here is for example one that I am working on:
<?php
// Load helpers
require_once(ITU_HELPERS . 'build-checkbox-list.php');
$checkboxes = new buildCheckboxList('quote_category');
cs_define_values('checkboxes', $checkboxes->get_defaults());
// Register "ITU Post based Carousel"
cs_register_element('itu-quotes-carousel', array(
// Define a localized title of your element and how it is labeled in the Element Library
'title' => __('ITU Quotes Carousel', 'itu-text-domain'),
// Define some values that we want to let users customize for this element
'values' => cs_compose_values('checkboxes'),
// Define the control navigation used to organize controls in the Inspector
'control_nav' => array(
'quote-carousel' => __('ITU Quote Carousel', 'itu-text-domain'),
'quote-carousel:setup' => __('Setup', 'itu-text-domain'),
),
// Define the controls that connect to our values.
'controls' => array(
array(
'keys' => $checkboxes->get_keys(),
'type' => 'checkbox-list',
'group' => 'quote-carousel:setup',
'label' => __('Choose categories', 'itu-text-domain'),
'options' => array(
'list' => $checkboxes->get_options()
)
)
),
// Connect a function used to render this element
'render' => 'render_itu_quotes_carousel',
));
function render_itu_quotes_carousel($data)
{
extract($data);
$categoriesarray = array();
foreach ($data as $key => $value) {
$testcheckbox = explode('_', $key);
if ($testcheckbox[0] == 'checkbox' && $value == "1") {
$categoriesarray[] = $testcheckbox[1];
}
}
$quotes = get_posts(array(
'post_type' => 'quote',
'numberposts' => -1,
'tax_query' => array(
'taxonomy' => 'quote_category',
'field' => 'term_id',
'terms' => implode(",", $categoriesarray),
'operator' => 'IN'
)
));
return "<div>Test</div>line2";
}
function renderQuotes($quotes)
{
$returnhtml = "";
foreach ($quotes as $quote) :
$author_name = get_field('_cmb_quote_author_name', $quote->ID);
$author_title = get_field('_cmb_quote_author_title', $quote->ID);
$author_company = get_field('_cmb_quote_author_company', $quote->ID);
$returnhtml .= "<div class=\"slide\">";
$returnhtml .= "<div class=\"leftquotemark\">";
$returnhtml .= "<img src=\"" . ITU_IMAGES . "quote_marks_open.png\" alt=\"Open quote mark\" class=\"leftquotemarkimage\">";
$returnhtml .= "</div><div class=\"quotecontent\">$quote->post_content";
$returnhtml .= "<div class=\"quoteauthor\"><strong>";
$returnhtml .= !empty($author_name) ? $author_name : $quote->post_title;
$returnhtml .= "</strong>";
$returnhtml .= !empty($author_title) ? ", " . $author_title : "";
$returnhtml .= !empty($author_company) ? ", " . $author_company : "";
$returnhtml .= "</div></div><div class=\"rightquotemark\">";
$returnhtml .= "<img src=\"" . ITU_IMAGES . "quote_marks_close.png\" alt=\"Open quote mark\" class=\"leftquotemarkimage\"></div></div>";
endforeach;
return $returnhtml;
}
My problem is with the render function. As soon as I use an html tag after the return statement, Cornerstone display the message: This element could not render due to invalid markup…
The code works well outside of the editor, but I cannot manage to have anything displayed within the editor.
Could you please explain to me what I am doing wrong instead of just directing me to the primer and reference pages? I read them already 10’000 times, but cannot figure how to fix this…
Thanks in advance,
Gil



