Skip to content

Instantly share code, notes, and snippets.

@robwent
Last active March 30, 2019 17:16
Show Gist options
  • Save robwent/f72c687e29d95137b0acf8436abf64de to your computer and use it in GitHub Desktop.
Save robwent/f72c687e29d95137b0acf8436abf64de to your computer and use it in GitHub Desktop.
Adds Joomla article alternative layout information as a class to the body tag. Use in your templates index.php file.
<?php
$app = JFactory::getApplication();
$view = $app->input->getCmd( 'view', '' );
$body_class = '';
if ( $view === 'article' ) {
$article = JTable::getInstance( "content" );
$id = $app->input->getInt( 'id' );
$article->load( $id );
$attribs = json_decode( $article->attribs );
if ( property_exists( $attribs, 'article_layout' ) ) {
$article_layout = str_replace( ':', '-', $attribs->article_layout );
$body_class .= ' article-layout-' . $article_layout;
}
}
?>
<body class="<?php echo $body_class; ?>">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment