143 Posts
pretobrazza
8 months ago
3
Topic

Hello,

In a blog Item view I want to render the titel and the fulltaxt of a corresponding article in a modal window. 
Everything works except that I get e.g. ::cck::100320::/cck:: as the fulltext

the code I use is:

data-title="<?php echo $this->escape($this->item->title); ?>" 
data-fulltext="<?php echo $this->item->fulltext; ?>"

Now the question is how I can render the fulltext of the article? I've looked everywhere and even asked AI but I don't find the ricght answer.

Please help me to realize this. I'm using Joomla 4 - Latest Seblod - Gantry 5
Bernard 



Get a Book for SEBLOD
157 Posts
Hableur
8 months ago
2
Level 1

Bonjour,

Avec Seblod, l'introtext et le fulltext sont sauvegardés dans le champ introtext de #__content, avec des spérataeurs du type

::cck::100320::/cck::, et fulltext ne contient que le séparateur.
Pour avoir le contenu, il faut utiliser un script beforeRender, et utiliser $cck->getValue('ad_introtext').

Ou alors prendre l'introtext directement et le découper avec une série d'explode(), mais...

With Seblod, the introtext and fulltext are saved in the introtext field of #__content, with separators like ::cck::100320::/cck::, and fulltext only contains the separator.
To get the content, you need to use a beforeRender script, and use $cck->getValue('ad_introtext').

Alternatively, you can take the introtext directly and split it with a series of explode(), but...


143 Posts
pretobrazza
8 months ago
1
Level 2

Thank you for your reply! (I can read it perfectly in French but rather write in English ;) to avoid too many spelling mistakes )

I know that everything sits in the field introtext (SeblodID, introtext and fulltext) but whatever I try on that field, nothing renders. Yet in the database it is filled. It seems to me that rendering that specific field is blocked in a Joomla page. 

I did try $cck->getValue('art_introtext') already in the past days but then I get the error  Call to a member function getValue() on null  

That is because there is some code I have to place to initiate Seblod and give #cck a meaning ... and thats's where I don't find any documentation. (Also tried Gemini, OpenAI and Groq but to no use)

I'd be gratefull to be able to see the code which will get  $cck->getValue('art_introtext') to work outside Seblod. 

Un très grand merci en avance !  

143 Posts
pretobrazza
7 months ago
0
Level 3

Hmm this forum is as dead as a bat but with chatgpt I tried and succeeded to render Seblod's ::fulltext:: in a modal window out of a featured blog view in Joomla. 

In ‎/templates/g5_hydrogen/html/com_content/featured/default_item.php" in template "g5_hydrogen  I used the code:

 <?php if ($params->get('show_title')) : ?>
    <h4 class="item-title" itemprop="headline">
        <?php if ($params->get('link_titles') && $params->get('access-view')) : ?>
            <a class="featured-title" href="#" data-bs-toggle="modal" data-bs-target="#exampleModal"
               data-title="<?php echo $this->escape($this->item->title); ?>"
			   data-fulltext="<?php echo Route::_(RouteHelper::getArticleRoute($this->item->slug, $this->item->catid, $this->item->language)); ?>"
               itemprop="url">
                <h5 style="text-transform: uppercase;"><?php echo $this->escape($this->item->title); ?></h5>

and just before the </body> tag I put this 

<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-dialog-scrollable">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel"></h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <!-- Content will be filled dynamically via JavaScript -->
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo Text::_('JTOOLBAR_CLOSE'); ?></button>
            </div>
        </div>
    </div>
</div>
<script>
    // JavaScript to handle modal content population
    document.addEventListener("DOMContentLoaded", function () {
        var modalTriggerElements = document.querySelectorAll('[data-bs-toggle="modal"]');
        modalTriggerElements.forEach(function (element) {
            element.addEventListener("click", function () {
                var title = this.getAttribute('data-title');
                var articleUrl = this.getAttribute('data-fulltext'); // Assuming the link to the article is stored in the 'href' attribute
                var modalTitleElement = document.querySelector('.modal-title');
                var modalBodyElement = document.querySelector('.modal-body');
                modalTitleElement.textContent = title;
                
                // Make an AJAX request to fetch the content of the article
                var xhr = new XMLHttpRequest();
                xhr.onreadystatechange = function() {
                    if (xhr.readyState === XMLHttpRequest.DONE) {
                        if (xhr.status === 200) {
                            // On success, extract the content of the div with id containing "art_fulltext"
                            var articleContent = xhr.responseText;
                            var parser = new DOMParser();
                            var doc = parser.parseFromString(articleContent, 'text/html');
                            var fulltextContent = doc.querySelector('.cck_art_fulltext').innerHTML;
                            
                            // Update the modal body with the extracted content
                            modalBodyElement.innerHTML = fulltextContent;
                        } else {
                            // On error, display a message or handle it as per your requirement
                            modalBodyElement.innerHTML = 'Error fetching article content.';
                        }
                    }
                };
                xhr.open('GET', articleUrl, true);
                xhr.send();
            });
        });
    });
</script>

I hope this will be usefull to anyone encountering the same problem :) 

Get a Book for SEBLOD