Home with exception

Hello,

I have a «cosmetic» problem

My Home Button ist a logo with a text

if the user visit the page he can see only the logo without text
if the user on a page but not the homepage a he click on the home button
he arrived on the homepage and see the logo with text.

how can solved the little problem without generate double content
and without js.

greetings perry

If you’re using a different template for your homepage compared to all the other pages, you can use that in an if statement.

“If template is different than home => display text”

Let me know if you need help with that :wink:

Do I get this right, that you want a different behavior of the logo depending on whether the home page is visited directly or if the user comes from another page?

If so, I think you could achieve this with cookies. But what is your use case for showing a different logo?

thank you @texnixe @Thiousi for your answers.

if found a solution:

home button with link to /index.php
if the user visit first time the homepage
www.myhomepage.com
logo without text

if the user use the home button (/index.php)
logo with text

      <a href="/index.php">
      <div id="logo-wrapper">
        <ul id="logo-symbol">
          <li><h1>logo</h1></li>
        </ul>
        <?php
        $url= $_SERVER['REQUEST_URI'];
        if ($url == '/index.php')
        {
          ?>

                <ul id="logo-title">
                  <li>text</li>
                  <li>text</li>
                </ul>

               
         <?php                
          }
              ?>
      </div>
       </a>

Hey! I think I understand what you’re looking to do (determine whether a visitor has seen your homepage, yet), but I wanted to offer a broader solution. For anyone else coming here looking for a way to alter the appearance of global page elements based on the current page, this is still relevant information!

The above may work, but doesn’t really look like a Kirby-specific solution— in fact, most people will be using mod_rewrite and have URLs without the index.php script name. Plus, Kirby has so many built-in helpers that you can probably avoid comparing strings to super global properties. Take $page->isHomePage() for example!

This kind of thing should be as simple as using a bit of CSS, but check out one really neat trick, first.

<body class="<?php echo $page->slug() ?>">

You’ll end up with something like this, if your Homepage has the slug home:

<body class="home">

It’s also possible, as @texnixe noted, to set a Cookie— you could just as easily add a class to body based on the state of that cookie.

Either way, with CSS, you can use a scoped rule to target the header content you want to show or hide:

/* Default appearance */
.logo-title { display: none; }

/* Appearance when on the homepage */
body.home .logo-title { display: none; }

/* Appearance based on cookie state */
body.already-viewed-homepage .logo-title { display: none; }

/* The same works for any other page slug! */
body.contact .logo-title { display: none; }

You can even add multiple classes (i.e. one for $page->template())! I typically use a helper function to add them more efficiently.

:v:

1 Like

@AugustMiller Yes, I would prefer that to the solution with the index.php as well.

@AugustMiller thank you for answer and the tip $page->isHomePage()

i found another solution with $_SESSION
set the session var in all templates but not in home template

       <div id="logo-wrapper">
            <a href="/">

        <ul id="logo-symbol">
          <li><h1>logo</h1></li>
        </ul>
        <?php
        
        if ($_SESSION["homebutton"] == 1 and $page->isHomePage())
        {
          ?>

                <ul id="logo-title">
                  <li>text</li>
                  <li>text</li>
                </ul>

               
               
<?php                
}
    ?>
       </a>
      </div>

why the /index.php is not a good solution ?