Fwd: Template <body id="different Ids">

69 views
Skip to first unread message

Alex

unread,
Aug 30, 2012, 3:36:37 PM8/30/12
to dot...@googlegroups.com



>
> Hi,
>
> I am on 2.1.What is the best approach to handle different body ids
> on a template?
>
> I am doing a responsive design template and it requires that each
> layout has its own body id tag.
>
> Thanks,
>
> Alex

Mark Pitely

unread,
Aug 30, 2012, 4:06:27 PM8/30/12
to dot...@googlegroups.com
Alex,

You certainly could use a variable - how are you going to tell which (of the seven) each page is going to have?
You could make a structure that has page/folder cross-referenced the correct body id.

Here's some code that does this thing, roughly. Old pull format, sorry, but you can get the idea.
Structure has a foldername, a color for the menu (i.e. <div class="$menucolor">), whether to have a crumbtrail, and the ID of the contact that belongs on it.


##Get the URL of the page first
#set ($topurl=$VTLSERVLET_URI.substring(1, $VTLSERVLET_URI.indexOf('/',1)))

##READ IN THE DATA FROM THE TEMPLATE STRUCTURE
 #set ($query="+structureName:Templates  +Templates.folder1:*$topurl*")
#pullContent($query '1' 'modate Desc')

#foreach($conT in $list)
#set ($footer=$conT.contactid)
#set ($crumb=$conT.removecrumbtrail)
#set ($menucolor=$conT.color)
#if ($UtilMethods.isSet($conT.menubottom))
#set ($menubottom=$conT.menubottom)
#end
#end
##OF FOREACH

##END PULL OF TEMPLATE


Mark Pitely
Marywood University


Alex

unread,
Aug 30, 2012, 6:19:47 PM8/30/12
to dot...@googlegroups.com
Mark:

Thanks a lot!


What do you mean by "page/folder" cross-referenced?

What you are stating is for example, I create a structure say "Body"
on that contains

Page
Folder
Body ID

Example:

Page: index.html
Folder: es
Body Id: page1

Then, on the template instead of putting the body tag I put a
container with the code?

This will be very useful!

Thanks,

Alex
> --
> You received this message because you are subscribed to the Google
> Groups "dotCMS User Group" group.
> To post to this group, send email to dot...@googlegroups.com.
> To unsubscribe from this group, send email to dotcms+un...@googlegroups.com
> .
> For more options, visit this group at http://groups.google.com/group/dotcms?hl=en
> .

Alex

unread,
Aug 30, 2012, 11:12:39 PM8/30/12
to dot...@googlegroups.com
Maria:

How can I search for a directory name in dotCMS 2.1?

Here is the pull i put in a container.  It seems taht dotcms uses the conFolder with an identifier.  Is there a way I can take the identifier for $topurl?
:

##Get the URL of the page first
#set ($topurl=$VTLSERVLET_URI.substring(1, $VTLSERVLET_URI.indexOf('/',1)))

#foreach($con in $dotcontent.pull("+structureName:Templates +conFolder:$topurl",1,"modDate desc"))

#set($bodyId=$con.bodyId)

<body id="$bodyId">
#end

Thanks,
#set ($query="+structureName:Templates  +Templates.folder1:*$topurl*")

Maria Ahues Bouza

unread,
Aug 30, 2012, 11:54:23 PM8/30/12
to dot...@googlegroups.com
try this

#set($currentFolder = $folderAPI.findCurrentFolder($topurl,$host))

this returns a Folder, to get the identifier do $currentFolder.identifier
Community Manager

dotCMS
Main: 305.900.2001
Fax: 305.397.2579
www.dotcms.com
http://www.twitter.com/dotCMS
http://www.facebook.com/dotCMS
http://www.twitter.com/mabouza

Please consider the planet before printing this email.

Alex

unread,
Aug 31, 2012, 12:08:42 AM8/31/12
to dot...@googlegroups.com
This is what the $currentFolder outputs:

com.dotmarketing.portlets.folders.model.Folder@48a0386f[name=,sortOrder=0,showOnMenu=false,hostId=,title=,filesMasks=,defaultFileType=,iDate=Fri Aug 31 00:05:25 EDT 2012,type=folder,owner=,inode=,identifier=]

If I print out $currentFolder.identifier .. it does not display anything.

Alex

Alex

unread,
Aug 31, 2012, 9:07:37 AM8/31/12
to dot...@googlegroups.com
Just tested this on the demo too and I don't get the current folder identifier either:




Here is the widget I am using
##Get the URL of the page first
#set($topurl=$VTLSERVLET_URI.substring(1, $VTLSERVLET_URI.indexOf('/',1)))



#set($currentFolder = $folderAPI.findCurrentFolder($topurl,$host))

<p><strong>This is currentFOLDER</strong>:  $currentFolder</p>
<p><strong>HOST INFO</strong>= $host<p>
<p><strong>HOST Identifier</strong>= $host.identifier<p>
  <p><strong>TOPURL </strong>= $topurl<p>

  <p><strong>Current Folder Identifier </strong>= $currentFolder.identifier<p>

#foreach($con in $dotcontent.pull("+structureName:Templates +conFolder:$!{currentFolder.identifier}",1,"modDate desc"))


<body id="$con.bodyId">
  
  TEST
#end​

Maria Ahues Bouza

unread,
Aug 31, 2012, 11:59:44 AM8/31/12
to dot...@googlegroups.com
The issue was $topurl. You were using about-us and the path needs the /. It needs to be /about-us/.

I changed test.html in demo to test and it works now.

Alex

unread,
Aug 31, 2012, 3:44:12 PM8/31/12
to dot...@googlegroups.com
I could not see the demo before it  got deleted.

You mean I have to define the topurl like:

#set($topurl= "/$VTLSERVLET_URI.substring(1, $VTLSERVLET_URI.indexOf('/',1))/")

I do get $topurl as "/directory/", but I still do not get the folder identifier.

I also noticed that if I am in a directory such as /directory/subdirectory/  $topurl gives me only the directory and not the subdirectory.

Alex

Maria Ahues Bouza

unread,
Aug 31, 2012, 3:56:20 PM8/31/12
to dot...@googlegroups.com
Not sure what you're doing differently but in demo, I changed the call directly, didn't update topurl, changed it to be /about-us/ and that worked.

Make sure that you're using the substrings properly, the code in demo was not returning the correct topurl, it was only returning about-us without the /

Your topurl is not returning the /subdirectory/ because you're doing an indexOf on the first "/". 

Mark Pitely

unread,
Aug 31, 2012, 4:01:05 PM8/31/12
to dot...@googlegroups.com
Alex,

That code I sent was not exactly perfect for what you wanted.

This will pull the full path name, cropping off any file at the end, and include the leading /, if you like:
#set ($topurl=$VTLSERVLET_URI.substring(0, $VTLSERVLET_URI.lastIndexOf('/')))
#set ($topurl=$topurl+"/")
$topurl

Mark


Brad Rice

unread,
Aug 31, 2012, 4:57:02 PM8/31/12
to dot...@googlegroups.com
Not sure if this will help, but I have been doing something similar.

#set($delims = '/')
#set($path = $request.getRequestURI())
#set($path_array = $path.split($delims))

This gives you an arraylist of the folders in the path.
> --
> You received this message because you are subscribed to the Google Groups
> "dotCMS User Group" group.
> To post to this group, send email to dot...@googlegroups.com.
> To unsubscribe from this group, send email to
> dotcms+un...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/dotcms?hl=en.



--
Brad Rice
brad...@gmail.com
~
“Silence in the face of evil is itself evil: God will not hold us
guiltless. Not to speak is to speak. Not to act is to act.” - Dietrich
Bonhoeffer

Alex

unread,
Aug 31, 2012, 5:23:35 PM8/31/12
to dot...@googlegroups.com
Got it!  I am trying to the get the file identifier so I can determine the type of body tag the template should display.  Here is the loop:

##From Mark - Thank You, Mark!


#set($topurl=$VTLSERVLET_URI.substring(0, $VTLSERVLET_URI.lastIndexOf('/')))
#set($topurl=$topurl+"/")

#set($currentFolder = $folderAPI.findCurrentFolder('$topurl','$host'))

<p>$currentFolder.identifier</p> 
<p>$!{currentFolder.identifier}</p>



#foreach($con in $dotcontent.pull("+structureName:Templates +conFolder:$!{currentFolder.identifier}",1,"modDate desc"))


<body id="$con.bodyId">
  
 
#end​

Alex

unread,
Aug 31, 2012, 5:38:15 PM8/31/12
to dot...@googlegroups.com
Just to be more specific:

When I search a host/file field I need to use the identifier of the host/file so +conFile is a host field.

Thanks,

Alex

Alex

unread,
Aug 31, 2012, 5:50:28 PM8/31/12
to dot...@googlegroups.com
Sorry, what I need is the FOLDER identifier, not the file.


Alex

Alex

unread,
Aug 31, 2012, 10:11:21 PM8/31/12
to dot...@googlegroups.com
ok, I figured out what was wrong.  Now, the question is:

When I do a pull with a host/folder field what exactly do I need to put in that field to make a pull and get a results.  Neither the identifier or the inode of the folder seems   to be doing the job.

#foreach($con in $dotcontent.pull("+structureName:Templates +conFolder:$!{currentFolder.identifier}",1,"modDate desc"))


<body id="$con.bodyId">
  
 
#end​

I am starting to hate the disk cache.  I have to clear it every time I make changes to my containers.

Alex

Alex

unread,
Sep 1, 2012, 10:44:40 PM9/1/12
to dot...@googlegroups.com
For those ones who may encounter this problem the host/folder field searches for the folder inode so the code to work should look like this.  I put this in a container and it places the body tag of the template:

##Get the URL of the page first


#set($topurl=$VTLSERVLET_URI.substring(0, $VTLSERVLET_URI.lastIndexOf('/')))
#set($topurl=$topurl+"/")

#set($currentFolder = $folderAPI.findCurrentFolder("$topurl",$host))

#foreach($con in $dotcontent.pull("+structureName:Templates +conFolder:$currentFolder.inode",1,"modDate desc"))


#set($bodyId = $!{con.bodyId})
  
<body id="$bodyId">

Maria Ahues Bouza

unread,
Sep 4, 2012, 5:47:07 PM9/4/12
to dot...@googlegroups.com
Alex,

Would you like to submit this to codeshare?

Thanks
Maria

Alex

unread,
Sep 4, 2012, 5:48:09 PM9/4/12
to dot...@googlegroups.com
Sure go ahead!  You and Mark are the ones that came up with the code I just tested it.

I think it is best used if you just set all he variables and then use the $variableName through out the template.  This is very useful in a responsive template.
Reply all
Reply to author
Forward
0 new messages