I created a custom element using the Primer and Reference docs. So far the element is available and I can add it to my page. All of the fields show up fine. The only issue I’m having is the styles. I can pass them to my render
function and get some things working with inline styles, but I can’t do that for everything as I need to target pseudo elements as well. I tried registering the style
callback, but none of the styles show up.
I am registering my element like so:
private function register() {
cs_register_element( 'cscompanion-eri-file-library', [
'title' => __( 'ERI File', 'cornerstone-companion' ),
'values' => [
'type' => cs_value( 'link', 'attr', false ),
'align_content' => cs_value( 'left', 'attr', false ),
'content_margin' => cs_value( '0rem', 'attr', false ),
'background_color' => cs_value( 'transparent', 'attr', false ),
'background_color_hover' => cs_value( 'transparent', 'attr', false ),
'text_color' => cs_value( 'transparent', 'attr', false ),
'text_color_hover' => cs_value( 'transparent', 'attr', false ),
],
'builder' => [ $this, 'builder' ],
'style' => [ $this, 'style' ],
'render' => [ $this, 'render' ],
] );
} // End register()
And my style looks like this:
public function style() {
$download_class = $this->download_class;
ob_start();
?>
.$_el {
margin: $content_margin;
text-align: $align_content;
}
.$_el .<?php echo esc_attr( $download_class ); ?>.button {
background-color: $background_color;
color: $text_color !important;
}
.$_el .<?php echo esc_attr( $download_class ); ?>.button:hover {
background-color: $background_color_hover;
color: $text_color_hover !important;
}
<?php
return ob_get_clean();
} // End style()
And lastly, my render
callback:
public function render( $data ) {
extract( $data );
$incl_class = $class ? ' class="' . $class . '"' : '';
$incl_title = $title ? ' title="' . $title . '"' : '';
$incl_desc = $desc ? ' desc="' . $desc . '"' : '';
$incl_formats = $formats ? ' formats="' . $formats . '"' : '';
// Print
return '<div id="' . esc_attr( $style_id ) . '"' . $incl_class . '>' .
do_shortcode( '[' . $this->shortcode . ' id="' . esc_attr( $id ) . '" type="' . esc_attr( $type ) . '"' . $incl_title . $incl_desc . $incl_formats . ']' ) .
'</div>';
} // End render()
I read in another forum topic that .$_el
was being replaced with &
, but doing &
did not make a difference. I also tried $el
and $_el
. Nothing is working, and it seems your documentation is outdated. Any suggestions?
Here is my full script if it helps: GitHub Gist.
Thanks in advance.