1
playsome
place div on homepage only
  • 2011/3/24 1:16

  • playsome

  • Not too shy to talk

  • Posts: 197

  • Since: 2009/4/15


Hello, quick question about smarty. In my theme I want to code in a div but have it display on the top page only, the div will be above the footer and stretch the full width of the theme so i dont think i can do it with a block, i need some smarty code that could accompish this

example

<{if body_id == "system"}>
<
div class="mydiv">
...
</
div>
<{/if}>


is there some smarty code that could be used to accomplish this?

Thanks

2
jimmyx
Re: place div on homepage only
  • 2011/3/24 1:27

  • jimmyx

  • Quite a regular

  • Posts: 338

  • Since: 2007/7/18


try this

<{if $smarty.server.PHP_SELF=='/index.php'}> 
...
<{else}>
...........

<{/if}>

3
novlang1984
Re: place div on homepage only

Or try this :

theme.html
Quote:
<body id="<{$xoops_dirname}>">


... and
Quote:
<{if $xoops_dirname == 'system'}>
<div>Hello world!</div>
<{/if}>

4
bjuti
Re: place div on homepage only
  • 2011/3/24 16:48

  • bjuti

  • Just can't stay away

  • Posts: 871

  • Since: 2009/1/7 2


AFAIK It should not work if you have defined module for start page.

5
novlang1984
Re: place div on homepage only

If you choose a module for homepage, just enter his dirname (= module folder name) like this :

Quote:
<{if $xoops_dirname == 'module-dirname'}>


It should work

6
playsome
Re: place div on homepage only
  • 2011/3/24 18:22

  • playsome

  • Not too shy to talk

  • Posts: 197

  • Since: 2009/4/15


Hi, thanks for your replies, I will them a try.

Thank you.

7
bjuti
Re: place div on homepage only
  • 2011/3/24 23:51

  • bjuti

  • Just can't stay away

  • Posts: 871

  • Since: 2009/1/7 2


Quote:

If you choose a module for homepage, just enter his dirname (= module folder name) like this :

Quote:

<{if $xoops_dirname == 'module-dirname'}>



It should work


But what if the start module is eg news... and i put $xoops_dirname == 'news' and then go to news module? There also be the same div :)

8
novlang1984
Re: place div on homepage only

You're right, div will be displayed on all news module pages.

Except if you put the code above into news template, directly
(if I well remember, nw_news_index.html)

But in this case, it does not a good solution because the div has to be under canvas div and not in content one.

So - if you really want this div only on the homepage - a solution would be
- to use a simple page made with Ghost module
- and try to play with modules blocks to have a nice home page

You will have to enter at the end of theme.html
<{if $xoops_dirname == 'ghost'}>
<
div>Hello world</div>
</
div>


... you would not have an aspirin for me ?

9
bjuti
Re: place div on homepage only
  • 2011/3/25 15:01

  • bjuti

  • Just can't stay away

  • Posts: 871

  • Since: 2009/1/7 2


Yup, that is my solution also... It would be nice someone to make exception for this issue, eg. home page always should be =='homepage' or =='toppage'?

10
trabis
Re: place div on homepage only
  • 2011/3/25 19:54

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Here is a good solution, follow me:

1 - Create a folder modules/system/preloads
2 - Create a file modules/system/preloads/core.php
3 - Edit core.php and insert this:
<?php
defined
('XOOPS_ROOT_PATH') or die('Restricted access');

/**
 * Class to allow <{if $homepage}>Your code here<{/if}> in templates
 * @author trabis
 */
class SystemCorePreload extends XoopsPreloadItem
{
    
//We are using this header hook because cached pages may not hit the footer.php
    
function eventCoreHeaderAddmeta($args)
    {
        if (
defined("XOOPS_STARTPAGE_REDIRECTED") || (isset($GLOBALS['xoopsOption']['template_main']) && $GLOBALS['xoopsOption']['template_main'] == "db:system_homepage.html")) {
            if (
is_object($GLOBALS['xoopsTpl'])) {
                
$GLOBALS['xoopsTpl']->assign('homepage' ,true);
            }
        }
    }
}
?>


You should now be able to use this code in any template:
<{if $homepage}>Your code here<{/if}>


Login

Who's Online

179 user(s) are online (90 user(s) are browsing Support Forums)


Members: 0


Guests: 179


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Mar 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits