Foren

Issue: Access to $request in a template called by ajax

Edouard Perr, geändert vor 11 Jahren.

Issue: Access to $request in a template called by ajax

Junior Member Beiträge: 30 Beitrittsdatum: 20.08.12 Neueste Beiträge
Hello there,

I am facing an issue I can't manage to resolve.
I have a particular document template in wich I call via AJAX (with jQuery.ajax) another template to insert into it. The web content implementing this template is put in a web display content portlet. Here is a part of the code:

(Note that I am doing a foreach clause to aggregate several articles as a list)
<script type="text/javascript">
function grabArticle(articleId, groupId, lastVersion) {
    var article = "";
    jQuery.ajax({
        url: "/c/journal/view_article_content?groupId=" + groupId + "&articleId=" + articleId + "&version=" + lastVersion + "&p_p_state=exclusive",
        success: function(data) {
            articleView = data;
        },
        async: false
    });
    return articleView;
}

[...Foreach on a articleId list, and call to grabArticle() and innerHtml to fill a particular div...]

</script>

<h2>Some html to design the list</h2>

<p>Display of velocity variable "request" :</p> $request



In the previous template, I can display all the parameters of the $request object. I can access for example the languageId.
The issue is in the template of the articles I am grabbing. I can access to the article fields, but he $request is always empty :

<p>Display of velocity variable "request" :</p> 
$request
<h3 class="trip-title"> <a href="/article?code=$reserved-article-id.data">$title1.data</a> </h3> <p> <span class="duration-label">$libelle-duree.data</span> <span>from $fromprice.data € </span> </p> <p>$short-description.data</p>


Some basic stuff here. But I am not able to access the Request velocity variable. The $request is resolved but instead of displaying the content with parameters, it just displays {}.

I noticed that it is the same behaviour if I clic on "View" link in the control panel/Web content. However it's woking fine if I put an article alone in a Web content display.
To specify, I unchecked the "cacheable" property in the template at the creation.

What can I do to access to the $request ?

Thanks.