Announcement

Collapse
No announcement yet.

Variable within a document.write expression

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Variable within a document.write expression

    I am trying to have a javascript file write some code including an image defined by a variable, something like this:
    Code:
    document.write('<actinic:variable encoding="perl" selectable="false" name="CompanyLogoImage" />;')
    The javascript executes and the phrase in the code above is written out but without functionality.
    Can a variable be made to work within a javascript expression of document.write or is it not possible?

    Similarly, I am also not able to get <actinic:block php="true" > to execute from within a javascript document.write expression.

    (My reason is that I am recoding a client site and do not want to throw the baby out with the bathwater by getting rid of all his existing javascript layout elements, wishing merely to modify them to function with variables rather than full url hard coding.)

    Thank you.
    Jonathan Chappell
    Website Designer
    SellerDeck Website Designer
    Actinic to SellerDeck upgrades
    Graphicz Limited - www.graphicz.co.uk

    #2
    CompanyLogoImage isn't a simple variable containing a bit of text. It's a Selector that lays out a complete Layout - Standard Company LogoImage. It contains:
    Code:
    <actinic:block if="%3cactinic%3avariable%20name%3d%22HomePageType%22%20%2f%3e%20%21%3d%20%270%27">
    <a href="<actinic:variable name="HomePageURL" />">
    </actinic:block>
    <img
    	src="<actinic:variable name="CompanyLogoFileName" />"
    	width="<actinic:variable name="CompanyLogoWidth" />"
    	height="<actinic:variable name="CompanyLogoHeight" />"
    	border="0"
    	alt="<actinic:variable name="StoreName" />"
    	title="<actinic:variable name="CompanyName" /> <actinic:variable name="StoreName" />"
    	class="logoimage" />
    <actinic:block if="%3cactinic%3avariable%20name%3d%22HomePageType%22%20%2f%3e%20%21%3d%20%270%27">
    </a>
    </actinic:block>
    Sticking single quotes around that will lead to a multi-line string which JavaScript doesn't do. Thus it's probably the newlines that are breaking your JavaScript.

    As for the PHP, without seeing any code it's hard to comment.
    Norman - www.drillpine.biz
    Edinburgh, U K / Bitez, Turkey

    Comment


      #3
      Sorry, bad coice of variable:

      This is javascript I cannot make work:

      Here is the placeholder

      Code:
      <script language="javascript" type="text/javascript" src="my-javafile.js"></script>
      Here is the content of the file

      Code:
      document.write("<a href='shoponline.html'><img border=0 src='<actinic:variable name="myimage" />' ></a>");
      I was trying to get round it by changing the content of the javascript files to simple files that can be included and using the javascript files to include them but I cannot get that to work either:

      IE

      simple text file contains:
      Code:
      <a href='shoponline.html'><img border=0 src='<actinic:variable name="myimage" />'></a>
      javascript file becomes:

      Code:
      document.write("<actinic:block php="true" >include 'simple-text-file.txt';</actinic:block>");
      I hope this is a little clearer

      Thank you
      Jonathan Chappell
      Website Designer
      SellerDeck Website Designer
      Actinic to SellerDeck upgrades
      Graphicz Limited - www.graphicz.co.uk

      Comment


        #4
        Jonathan,
        Not sure I completely understand the requirements here, however from your code above I would have thought that embedding the code directly into the layout would be better. The main reason it's not working is that the contents of the file are not being parsed by SellerDeck, hence the variable is not being "replaced" with respective content.

        I don't quite understand why you don't want to put
        Code:
        <a href='shoponline.html'><img border=0 src='<actinic:variable name="myimage" /><a/>
        straight in the layout. If it is for some "other" functionality reasons then perhaps you could enlighten us as to the purpose and we can maybe suggest a better way to achieve the same result?
        Fergus Weir - teclan ltd
        Ecommerce Digital Marketing

        SellerDeck Responsive Web Design

        SellerDeck Hosting
        SellerDeck Digital Marketing

        Comment


          #5
          You can trick SD into expanding variables inside a JavaScript file with a bit of filetype trickery. I use this in my Accordion Menu so I can pass many setup variables into the file:
          Code:
          <!-- the following two lines trick Actinic into expanding Variables into a JavaScript file. N.B. the .css suffix is required and deliberate. -->
          <script>/*<link href="myscriptfile.css" rel="stylesheet" type="text/css">*/</script>
          <script type="text/javascript" src="myscriptfile.css"></script>
          The first line causes the file to be written with variable expansion. The second line loads is as JavaScript (the script tag doesn't care what the file extension is).

          File myscriptfile.css can either contain swathes of JavaScript and Variables or (better) a single line loading a library Layout containing all the code. That way you keep everything in the Library.

          The file is only written once, so should only use Site level variables.
          Norman - www.drillpine.biz
          Edinburgh, U K / Bitez, Turkey

          Comment


            #6
            Thanks Fergus. It is a very large site that I am recoding. The design I have been presented with uses JavaScript to insert some layout into many places. My reasoning was that it might be better to change the way the JavaScript worked rathe than trying to find and replace every instance of ot but it looks like that is what I will have to do!

            Thanks.
            Jonathan Chappell
            Website Designer
            SellerDeck Website Designer
            Actinic to SellerDeck upgrades
            Graphicz Limited - www.graphicz.co.uk

            Comment

            Working...
            X