ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Displaying code snippets

March 14, 2010 5:17pm

Subscribe [5]
  • #1 / Mar 14, 2010 5:17pm

    Trevor Davis

    39 posts

    EE 1.6.8 Build: 20100121
    PHP Version 5.2.11

    I want to display code snippets (sometimes EE and PHP) in my entries that are not highlighted using the syntax highlighter. I tried doing this:

    <pre><code>{exp:weblog:entries weblog="forms" limit="1" disable="categories|category_fields|member_data|pagination|trackbacks"}
    
     {exp:freeform:form form_name="{url_title}" form_id="{url_title}" template="{form_template}" notify="{form_notify}" return="{form_return}" required="{form_field search:required='y' backspace='1'}{field}|{/form_field}"}
    
      <h1>{title}</h1>
      <ol class="forms">
       {form_field}
        <li>
         {if "{label}"}
          <label for="{field}">{if "{required}" == "y"}<em class="required">*</em>{/if}{label}</label>
         {/if}
         {if "{type}" == "Text Input"}
          <input type="text" name="{field}" id="{field}" >
         {if:elseif "{type}" == "Textarea"}
          <textarea name="{field}" id="{field}"></textarea>
         {if:elseif "{type}" == "Checkbox"}
          <input type="checkbox" class="checkbox" name="{field}" id="{field}" >
         {if:elseif "{type}" == "Select" || "{type}" == "Multi-select" && "{options}"}
          <select name="{field}{if "{type}" == "Multi-select"}[]{/if}" id="{field}"{if "{type}" == "Multi-select"} multiple="multiple" size="4"{/if}>
           <?php $items = explode("|", '{options}'); ?>
           <?php foreach ($items as $item) { ?>
            <option value="<?php echo $item; ?>"><?php echo $item; ?></option>
           <?php } ?>
          </select>
         {if:elseif "{type}" == "Radio Group" && "{options}"}
          <ul class="group">
           <?php $items = explode("|", '{options}'); $count = 1; ?>
           <?php foreach ($items as $item) { ?>
            <li><input type="radio" class="radio" name="{field}" id="{field}<?php echo $count; ?>" value="<?php echo $item; ?>" >
            <label for="{field}<?php echo $count; ?>"><?php echo $item; ?></label></li>
            <?php $count++; ?>
           <?php } ?>
          </ul>
         {if:elseif "{type}" == "Checkbox Group" && "{options}"}
          <ul class="group">
           <?php $items = explode("|", '{options}'); $count = 1; ?>
           <?php foreach ($items as $item) { ?>
            <li><input type="checkbox" class="checkbox" name="{field}[]" id="{field}<?php echo $count; ?>" value="<?php echo $item; ?>" >
            <label for="{field}<?php echo $count; ?>"><?php echo $item; ?></label></li>
            <?php $count++; ?>
           <?php } ?>
          </ul>
         {/if}
        </li>
       {/form_field}
       <li class="buttons"><input type="submit" name="submit" value="submit" ></li>
      </ol>
     {/exp:freeform:form}  
    {/exp:weblog:entries}</code></pre>

    Since by default EE tags and PHP tags are not processed, I figured that would work fine. But, it ends up displaying this:

    <pre><code>{exp:weblog:entries weblog="forms" limit="1" disable="categories|category_fields|member_data|pagination|trackbacks"}
    
     {exp:freeform:form form_name="{url_title}" form_id="{url_title}" template="{form_template}" notify="{form_notify}" return="{form_return}" required="{form_field search:required='y' backspace='1'}{field}|{/form_field}"}
    
      <h1>{title}</h1>
      <ol class="forms">
       {form_field}
        <li>
                  </li>
       {/form_field}
       <li class="buttons"><input type="submit" name="submit" value="submit" ></li>
      </ol>
     {/exp:freeform:form}  
    
    {/exp:weblog:entries}</code></pre>

    So I guess it is processing the conditional tag? Anyone have a suggestion? Again, I do not want to use the syntax highlighting and do not want to process this code, just display it. Thanks in advance.

  • #2 / Mar 15, 2010 3:16am

    John Henry Donovan

    12339 posts

    Trevor,

    One way would be to use pMcode

    so just wrap you code in

    [ code ]Some pre-formatted text…[ / code]

    Although that gives you native syntax highlighting, just mentioning it for reference.

    You may well be able to override this with some CSS though.

    The other way is to include it in a textarea <textarea></textarea>

    Does that help?

  • #3 / Mar 15, 2010 10:38pm

    Trevor Davis

    39 posts

    Trevor,

    One way would be to use pMcode

    so just wrap you code in

    [ code ]Some pre-formatted text…[ / code]

    Although that gives you native syntax highlighting, just mentioning it for reference.

    You may well be able to override this with some CSS though.

    The other way is to include it in a textarea <textarea></textarea>

    Does that help?

    I did try using [ code ] [ / code] but since it added the syntax highlighting, I was trying to find another solution. Is there no way to disable to syntax highlighting without editing a core file?

    Does this still work the same way in EE 2.0?

  • #4 / Mar 16, 2010 3:43am

    John Henry Donovan

    12339 posts

    Trevor,

    I did try using [ code ] [ / code] but since it added the syntax highlighting, I was trying to find another solution. Is there no way to disable to syntax highlighting without editing a core file?

    Like I mentioned a quick way around this would be to use some CSS to override the syntax highlighting inline styles

    Something like this would do it.

    .codeblock span{
        color:#000000 !important;
    }
  • #5 / Mar 16, 2010 9:40pm

    Trevor Davis

    39 posts

    Trevor,

    I did try using [ code ] [ / code] but since it added the syntax highlighting, I was trying to find another solution. Is there no way to disable to syntax highlighting without editing a core file?

    Like I mentioned a quick way around this would be to use some CSS to override the syntax highlighting inline styles

    Something like this would do it.

    .codeblock span{
        color:#000000 !important;
    }

    Thanks, that is an easy way to override the syntax highlighting. I guess another issue that I’m having is that entities are not actually being encoded correctly. So &#x2026; is not being encoded as the … character, it actually shows &#x2026; I guess I don’t really understand why there is so much difficulty rendering code. It’s not like I have the allow-ee plugin installed, so why does EE’s rendering engine have so much trouble with this?

  • #6 / Mar 17, 2010 3:40am

    John Henry Donovan

    12339 posts

    Trevor,

    Do you have Automatically Convert High ASCII Text to Entities  set to Yes or No?

    Admin ›  Weblog Administration ›  Global Weblog Preferences

  • #7 / Mar 17, 2010 10:10am

    Trevor Davis

    39 posts

    Trevor,

    Do you have Automatically Convert High ASCII Text to Entities  set to Yes or No?

    Admin ›  Weblog Administration ›  Global Weblog Preferences

    It was set to No, but I changed it to Yes, and I’m still seeing the same result. It is wrapped in a pre tag, not sure if that makes a difference.

  • #8 / Mar 17, 2010 4:56pm

    Ingmar

    29245 posts

    Do you’ve got a link? I am afraid the [ code] tag really is your best option here.

  • #9 / Mar 17, 2010 9:26pm

    Trevor Davis

    39 posts

    Do you’ve got a link? I am afraid the [ code] tag really is your best option here.

    Just sent you a personal message with the link. Thanks!

  • #10 / Mar 18, 2010 3:16am

    John Henry Donovan

    12339 posts

    Trevor,

    It was set to No, but I changed it to Yes, and I’m still seeing the same result.

    This setting works for any entry after you have changed the setting. Can you go back and resave your entry to see if this makes a difference.

  • #11 / Mar 18, 2010 10:42am

    Trevor Davis

    39 posts

    Trevor,
    This setting works for any entry after you have changed the setting. Can you go back and resave your entry to see if this makes a difference.

    I went back and saved it, and I’m still seeing the same result. I even tried changing the entity to &hellip; to see if it make a difference, but it did not.

  • #12 / Mar 18, 2010 5:19pm

    Ingmar

    29245 posts

    I’m a little unclear on what issue you’re having, exactly. Can you show us a link? Tell us what you do, what you expect to happen and what does happen, please.

  • #13 / Mar 18, 2010 11:54pm

    Trevor Davis

    39 posts

    I’m a little unclear on what issue you’re having, exactly. Can you show us a link? Tell us what you do, what you expect to happen and what does happen, please.

    I sent you a personal message with the URL.

    Ideally, I want to wrap my code snippets in <pre><code> tags. I do not want syntax highlighting.

    When I use John’s suggestion of wrapping it in [ code ] tags, it does not encode the entities, it just displays the entity code.

    Let me know if you need me to resend the message.

  • #14 / Mar 19, 2010 10:37am

    Ingmar

    29245 posts

    Sorry, didn’t get any message. Can you please try again? Use the “MSG” button under my avatar, please, to email (I’m not using the PM system).

  • #15 / Mar 19, 2010 10:41am

    Trevor Davis

    39 posts

    Sorry, didn’t get any message. Can you please try again? Use the “MSG” button under my avatar, please, to email (I’m not using the PM system).

    Just tried again, let me know if you don’t receive it.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases