Search

I´m working in this project that loads each page via ajax, and every page has to have a litle custom javascript on it, to make it work correctly, what is the best way to include javascript code inside textareas?

the funny thing is that, using the typografy xslt, the code appears ok in the debug=results page, but not in the source code, it´s just not there.

How are you outputting your text areas? If you are using value-ofyou won't be getting anything other than the top level node in your text area. You'll have better luck using copy-of possibly....

Can you post your xml and xslt for that part (either here or using pastie.org)?

I´m using the typografy extention that comes with symphony:

</xsl:template>

  <!--<xsl:variable name="is-logged-in" select="/data/events/login-info/@logged-in"/>-->
  <xsl:template match="paginas/entry">
    <div class="page_content"  id="ajax_{titulo-da-pagina/@handle}" >
     <div class="banner_info">

      <!--<xsl:if test="$is-logged-in = 'true'">
        <xsl:text> &#8212; </xsl:text>
        <a class="editar" href="{$root}/symphony/publish/{../section/@handle}/edit/{@id}/">Edit</a>
      </xsl:if>-->

       <xsl:apply-templates select="conteudo-html/*" mode="html" />

       <!--<xsl:copy-of select="conteudo-html" />-->
    </div>
    <div class="banner_img">
      <xsl:if test="imagem">
      <img src="{$workspace}/{imagem/@path}/{imagem/filename}" alt="Assistência técnica em informática Duh PC - Maringá PR"  />
      </xsl:if>
    </div>
  </div>
</xsl:template>
  <xsl:template match="conteudo-html">
    <xsl:value-of select="conteudo-html"/>
  </xsl:template>
</xsl:stylesheet>

and the part of the xml that i have to output:

<paginas>
        <pagination total-entries="1" total-pages="1" entries-per-page="20" current-page="1" />
        <section id="7" handle="paginas">Paginas</section>
        <entry id="17">
            <data time="10:28" weekday="7">2011-04-24</data>
            <imagem size="133 KB" path="/uploads" type="image/png">
                <filename>contact.png</filename>
                <meta creation="2011-04-24T13:00:45-03:00" width="444" height="360" />
            </imagem>
            <conteudo-html><div id="contact_form">
<form id="contact_form" method="post" action="" enctype="multipart/form-data">
  <div class="form_div">
  <label>Nome</label>
    <input class="input" name="fields[nome]" type="text"  rel="validate(required)"/>
  </div>
  <div class="form_div">
  <label>Email</label>
    <input class="input" name="fields[email]" type="text" rel="validate(required, email)" />
    </div>
  <div class="form_div">
  <label>Telefone</label>
    <input class="input" name="fields[telefone]" type="text" rel="validate(required)" />
    </div>
  <div class="form_div">
  <label>Mensagem</label>
    <textarea class="textarea" name="fields[mensagem]" rows="15" cols="50" rel="validate(required)"></textarea>
    </div>
    <input name="send-email[sender-email]" value="fields[email]" type="hidden" />
    <input name="send-email[sender-name]" value="fields[nome]" type="hidden" />
    <input name="etm[contato-confirm][reply-to-email]" value="fields[email]" type="hidden" />
    <input name="etm[][reply-to-name]" value="fields[nome]" type="hidden" />
    <input name="send-email[subject]" value="Novo contato" type="hidden" />
    <input name="send-email[body]" value="fields[nome,email,telefone,mensagem]" type="hidden" />
    <input name="etm[contato][recipient]" value="admin" type="hidden" />
  <div class="form_div">
  <input class="button" name="action[contato]" type="submit" value="" />
  </div>
<div class="error_div"><ol></ol></div>
</form>
</div>

&lt;script type="text/javascript" src="workspace/js/validate.min.js">&lt;/script>
&lt;script type="text/javascript">
if($('#contact_form').length) {
    $('#contact_form').ketchup({
      validationAttribute: 'rel',
      errorContainer: $('.error_div'),

      initialPositionContainer: function(errorContainer, field) {
        //errorContainer = the error-container with all childs
        //field = the field that needs to get validated
      },
      positionContainer: function(errorContainer, field) {},
      showContainer: function(errorContainer) {
        errorContainer.show('fast');
      },
      hideContainer: function(errorContainer) {
        errorContainer.hide('fast');
      }
    });
&lt;/script>
}</conteudo-html>
            <titulo-da-pagina handle="contato">Contato</titulo-da-pagina>
        </entry>
    </paginas>

I´m using what i beleve to be the ninja techniche, correct me if i´m wrong.

In this instance you don't really need to use the ninja technique because (as far as I can tell) you are not trying to alter your output. In fact you just want to output it exactly as you entered it.

In which case <xsl:copy-of> is a good safe bet. If you change you're template to the below you should get your javascript outputting as you want:

<xsl:template match="paginas/entry">
<div class="page_content"  id="ajax_{titulo-da-pagina/@handle}" >
 <div class="banner_info">

   <xsl:copy-of select="conteudo-html/*"/>

</div>
<div class="banner_img">
  <xsl:if test="imagem">
  <img src="{$workspace}/{imagem/@path}/{imagem/filename}" alt="Assistência técnica em informática Duh PC - Maringá PR"  />
  </xsl:if>
   </div>
 </div>
</xsl:template> 

Let me know how you get on. Using <xsl:copy-of select="conteudo-html/*"/> will give you all nodes inside the element which is what I think you want here.

That did work fine, thanks a lot.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details