Quantcast
Channel: Joomla! Forum - community, help and support
Viewing all articles
Browse latest Browse all 1321

General Questions/New to Joomla! 4.x • display the custom_html module's Note field in the frontend

$
0
0
ChatGTP gave me this code to display the custom_html module's Note field in the frontend. But it is not working.
J 4.4.6

Does anyone know why?

Code:

<?phpdefined('_JEXEC') or die;use Joomla\CMS\Factory;use Joomla\CMS\HTML\HTMLHelper;use Joomla\CMS\Uri\Uri;// Ensure that the $module object is availableif (isset($module) && isset($module->id)) {    $moduleId = $module->id;    // Access the database    $db = Factory::getDbo();    // Prepare a query to fetch the module parameters    $query = $db->getQuery(true)        ->select('params')        ->from($db->quoteName('#__modules'))        ->where($db->quoteName('id') . ' = ' . $db->quote($moduleId));    // Set the query and load the result    $db->setQuery($query);    $paramsJson = $db->loadResult();    // Decode the module parameters    $moduleParams = json_decode($paramsJson);    $moduleNote = isset($moduleParams->note) ? $moduleParams->note : '';    // Add inline styles for the background image if set    $modId = 'mod-custom' . $moduleId;    if ($params->get('backgroundimage')) {        $wa = Factory::getApplication()->getDocument()->getWebAssetManager();        $wa->addInlineStyle('#' . $modId . '{background-image: url("' . Uri::root(true) . '/' . HTMLHelper::_('cleanImageURL', $params->get('backgroundimage'))->url . '");}', ['name' => $modId]);    }    // Output the Note field    echo '<div id="' . htmlspecialchars($modId, ENT_QUOTES, 'UTF-8') . '" class="mod-custom custom">';    echo htmlspecialchars($moduleNote, ENT_QUOTES, 'UTF-8');    echo $module->content;    echo '</div>';} else {    echo 'Module object not found';}?>

Statistics: Posted by modernmagic — Fri Jul 26, 2024 10:44 pm



Viewing all articles
Browse latest Browse all 1321

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>