When imbedding lots of html in a menu (question)

Having problems with DHTML Menu? There is usually somebody here who knows the answer.
Post Reply
User avatar
Maestro
Super Advanced
Super Advanced
Posts: 45
Joined: Fri Dec 24, 2004 12:48 am
Location: Fort Bragg, CA
Contact:

When imbedding lots of html in a menu (question)

Post by Maestro »

I like the Milonic Menu system sooo much that I would like to build entire page sub-sections in certain menu sections.

This has its problems though, as these were never intended to hold more than a line or two of imbedded html at the item level.

In PERL there is a way to assign large blocks of html without having to escape special chars (like single and double quotes) by setting the variable using a user specified set of delimiters.

Does anyone know of a way to do this in javascript?
So that I could (for example) do something like this..

Code: Select all

 
var theTextBlock = |||    /* the three ||| would be my custom delimiters */

<table background="#FFCCFF">
  <tr>
    <td>
      some content goes here
    </td>
    <td>
      some more content
    </td>
  </tr>
</table>

|||;
Notice that I am liberally using white space.
And, I could also place the background parameter in the table declaration inside of double quotes.

This is a simple example, and for all intents and purposes would not need to be imbedded between custom delimiters; but there are more complex examples where I could justify such a need.

Then, I could use the variable thusly..

Code: Select all

// Example, using a variable to insert my text block when "type=html"
with(milonic=new menuname("MyTest")){
style=MyTestStyle;
aI("type=html;text=" + theTextBlock + ";");
}
Any thought anyone?
User avatar
Maestro
Super Advanced
Super Advanced
Posts: 45
Joined: Fri Dec 24, 2004 12:48 am
Location: Fort Bragg, CA
Contact:

More info..

Post by Maestro »

In PERL and PHP, there is a method called a here-document which allows you to store a text string with all the white space and special chars included (no escaping) which can be used to set a single variable.

The variable can later be used when writing to a web page (for example).
Otherwise you would be stuck having to write it all into PRINT clauses.

This is a neat method, and could be useful to you and the rest of us, if such a method exists in javascript - do you know if it does?

One could then use this to write long blocks of html code, assigning it to a var , which could be inserted as the content for a type=text or type=html element.
User avatar
kevin3442
Milonic God
Milonic God
Posts: 2460
Joined: Sat Sep 07, 2002 12:09 am
Location: Lincoln, NE
Contact:

Post by kevin3442 »

Hi Tim,

A nice idea, but there's no such capability in javascript that I'm aware of. That's not to say that it doesn't exist of course ;) But I've been doing js for a good while and have never run across any such. As you've probably discovered through your own testing, the problem with trying your approach using plain string variables is that the string variable assignment typically must be made all on one line. The assignment does not continue across multiple lines, so you'll end up with an "unterminated string constant" error.

While there's nothing exacly like you proposed, there is a "continuation character" in js, to continue a string assignment across multiple lines. It's the backslash character (\). Like so:

Code: Select all

var stringVariable = "here is a string that \
is assigned on three sep\
arate lines of code";

alert(stringVariable);
The output of the alert() would be:

Code: Select all

here is a string that is assigned on three separate lines of code
Note that spaces directly before the \ are added to the string as spaces.

Combine that capability with the fact that single quotes need not be escaped within the Milonic aI() string, so you can use single quotes for your html attribute values (or leave the quotes out altogether, which usually works just fine). Your example from above would be:

Code: Select all

var theTextBlock = "\
<table background='#FFCCFF'>\
  <tr>\
    <td>\
      some content goes here\
    </td>\
    <td>\
      some more content\
    </td>\
  </tr>\
</table>";
and the menu item definition would be exactly as you had it:

Code: Select all

aI("type=html;text=" + theTextBlock + ";"); 
Haven't tried it, but in theory, it should work. Let us know will you?

Hope that helps,

Kevin
User avatar
Maestro
Super Advanced
Super Advanced
Posts: 45
Joined: Fri Dec 24, 2004 12:48 am
Location: Fort Bragg, CA
Contact:

It might help

Post by Maestro »

Escaping the line breaks is better than no extra white space, certainly.
However, I was hoping to create sections dynamically; one, (possibly) to go inside <div> sections (for the Milonic enviroment), the other for conventional presentation between <noscript> tags.

Unless I am willing to write a substitution translator for all the Milonic values that I hoped to dynamically generate, thereby introducing an extra layer of obsfucation, that in my experience would eventually go obsolete as the technology improves, I think I'll just design the site with smaller Milonics.

Thanks for the response though.

-Tim
Post Reply