Search
Other Sourcerer questions
Forum

sourcerer not allowing php and style code

Pete Gypps's Avatar Pete Gypps
Im trying to add the following > I press CODE and choose PGP for the php part and then add style part in the module after and it fails to load properly - any guides or info ?
{source}
  <?php
    // Get the ID of the category you want to display
    $category_id = 1;

    // Get the articles from the category
    $db = JFactory::getDbo();
    $query = $db->getQuery(true)
      ->select($db->quoteName(array('id', 'title', 'introtext')))
      ->from($db->quoteName('#__content'))
      ->where($db->quoteName('catid') . ' = ' . (int) $category_id);
    $db->setQuery($query);
    $articles = $db->loadObjectList();
  ?>

  <style>
  .ticker {
    width: 100%;
    overflow: hidden;
    position: relative;
  }

  .ticker ul {
    display: flex;
    position: absolute;
    white-space: nowrap;
    animation: ticker 10s linear infinite;
  }

  .ticker li {
    display: inline-block;
    padding: 0 20px;
    min-width: 500px;
  }

  @keyframes ticker {
    0% {
      transform: translate3d(0, 0, 0);
    }
    100% {
      transform: translate3d(-100%, 0, 0);
    }
  }
  </style>

  <div class="ticker">
    <ul>
      {source}
        <?php
          // Output the articles
          foreach ($articles as $article) {
            echo '<li>' . $article->introtext . '</li>';
          }
        ?>
      {/source}
    </ul>
  </div>
{/source}
Peter van Westen's Avatar Peter van Westen ADMIN
First off, you are nesting {source} tags. That is not valid syntax.

Also, see the documentation on better ways to load CSS:
docs4.regularlabs.com/sourcerer/the-basi...tyles-and-javascript
Please post a rating at the Joomla! Extensions Directory
Pete Gypps's Avatar Pete Gypps
ive tried adding it with JCE enabled and then press code and php > this works if only the php or atleast it displays the static content in the right place.

i then go to CODE and CSS then enter this and it breaks... >
<style>
.ticker {
width: 100%;
overflow: hidden;
position: relative;
}

.ticker ul {
display: flex;
position: absolute;
white-space: nowrap;
animation: ticker 10s linear infinite;
}

.ticker li {
display: inline-block;
padding: 0 20px;
min-width: 500px;
}

@keyframes ticker {
0% {
transform: translate3d(0, 0, 0);
}
100% {
transform: translate3d(-100%, 0, 0);
}
}
</style>
Peter van Westen's Avatar Peter van Westen ADMIN
If the editor breaks the code on saving, then that is an editor issue, not a Sourcerer issue.
See: docs4.regularlabs.com/sourcerer/faqs/tro...n-i-save-the-article

Again, with your earlier code, your syntax is incorrect.
You have a {source} block inside a {source} block. You can't do that:
{source}
  ...
  <div class="ticker">
    <ul>
      {source}
       ...
      {/source}
    </ul>
  </div>
{/source}
Please post a rating at the Joomla! Extensions Directory
Pete Gypps's Avatar Pete Gypps
no worries, i stripped the php and used only that and then put the style seet elsewhere and now works.
You can only post on the extension support forum if you have an active subscription and you log in

Buy a Pro subscription