Developer forum

Forum » Development » If Defined still don't work

If Defined still don't work


Reply

According to bug# 2922 (Application 19.0.0.1) the problem with If Defined tags having no effect on custom tags from the Page Template Extender, should be fixed

 

But on application 19.0.0.3 this still don’t work.

 

In my page template I have placed the following code

 

CIT:Test:1=<!--@CIT:Test:1--><BR>

<!--@If Defined(CIT:Test:1)-->

It works from Page template extender!<br>

<!--@EndIf(CIT:Test:1)-->

<!--@If Not Defined(CIT:Test:1)-->

           It DON'T work from Page template extender!<br>

<!--@EndIf(CIT:Test:1)-->

 

<br>

Global:Extranet.UserName=<!--@Global:Extranet.UserName--><BR>

<!--@If Defined(Global:Extranet.UserName)-->

           It works from standard<br>

<!--@EndIf(Global:Extranet.UserName)-->

 

And in my Page template extender i set the custom tag as followed

 

public class PageTemplateExtender : Dynamicweb.PageTemplateExtender

    {

        public override void RenderTemplate(Dynamicweb.Templatev2.Template parmTemplate)

        {

            parmTemplate.SetTag("CIT:Test:1", "#");

        }

    }

 

 

This generate the following output:

 

CIT:Test:1=#
It DON'T work from Page template extender!

Global:Extranet.UserName=k1
It works from standard


Replies

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply
According to release notes: http://engage.dynamicweb-cms.com/Releases-177.aspx that particular bug was fixed in version 19.1.0.0.

- Jeppe
 
Reply
Okay I made a mistake in the application version. I meant of course version 19.1.0.0 and 19.1.0.3.
 
Bug# 2922 Is “fixed” on version 19.1.0.0, but it still don’t work on 19.1.0.3?
 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply
We have recently become aware of an issue with the 19.1.0.3 release in which some dlls were missing or not updated. A fix is being finished right now, and will be available very soon.
 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply
However I have just testet your particular problem with your sample code on 19.1.0.3 and it works fine here.

Are you sure your PageTemplateExtender is being invoked?
 
Reply
Yes im sure, i get the following output:

 

CIT:Test:1=#
It DON'T work from Page template extender!

Global:Extranet.UserName=k1
It works from standard

The # after CIT:Test:1= is set in the page template extender

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply
Is it possible for me to get a copy of the site? This will make it easier for me to find the problem since I'm unable to reproduce it here.
 
Reply
I had a similar problem once, and as far as I remember, I came around it by using Dynamicweb.Frontend.PageView.Current().TemplatePage.SetTemplateValue("tag", "value"). But that was an earlier versioni, so I'm not sure how it will work today. But it would be easy to test with your existing code, Thomas:)

BR.
Lars
 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply
If I understand the problem correctly, then the issue isn't setting the value of the Template Tag but rather checking whether the value is set using "If Defined".
 
Reply
Yes, but it may be a timing issue that prevents the tag from being catched by If Defined in the first place, and if so, using the other approach may have a positive outcome.

That template is a plain Dynamicweb.Template, but as far as I remember it passes everything to TemplateV2, so you have to shots of having a tag rendered in a page template. I used this approach as well in this article for rendering dynamic tags: http://engage.dynamicweb-cms.com/default.aspx?id=361&articleid=155.

But ultimately, using an XSLT template instead will rule out the problem Thomas is describing completely.

BR.
Lars
 
Reply

Yes the issue is the If Defined not finding the tag, set in the page template extender.  As described in the bug #2922. So somebody must know something about this bug.

 

I have just tested with the :
Dynamicweb.Frontend.PageView.Current().TemplatePage.SetTemplateValue("CIT:Test:1", "#");

 

And it don’t work anymore L

 

And using XSLT template is not an issue at this stage of the project

 
Reply
Oh, sorry. Well, then there are only two options. Bugfix or:

<script type="text/javascript">
    if ("<!--@CIT:Test:1-->" != ""){
        //The tag is defined
    }else{
        //The tag is not defined
    }
</script>
 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply
Like I said before, this bug has been fixed and I've tested it in 19.1.0.3 and it works fine for me. So I need more info to go on in order to figure out why it doesn't work for you. A copy of the site would be a big help.
 
Reply
Just tested the following in 19.1.0.2, and both approaches work fine:

using

Dynamicweb;

using

Dynamicweb.Extensibility;

namespace

{

 

CustomModules    public class PageTemplateExtender1 : PageTemplateExtender

    {

 

        {

 

        public override void RenderTemplate(Dynamicweb.Templatev2.Template Template)            //TODO: Add code here

            Template.SetTag(

            Dynamicweb.Frontend.

        }

    }

}

And in the template:

<!--@If Defined(CIT:Test:1)-->
Test 1
<!--@EndIf(CIT:Test:1)-->

<!--@If Defined(CIT:Test:2)-->
Test 2
<!--@EndIf(CIT:Test:2)-->

"CIT:Test:1", "#");PageView.Current().TemplatePage.SetTemplateValue("CIT:Test:2", "#");
 
Reply
Ahhh… found it, in my custom default.aspx I have some functionality to render global paragraphs to specific areas or languages and this is causing the problem.
 
Sorry, my mistake
 
Thanks for your help
 
Reply
Glad you found it:)

 

You must be logged in to post in the forum