0

I don't even know if this is possible but hopefully someone will be able to point me in the right direction.

Basically I want to know if there is a way of getting the css class of a div and then displaying content based on that class.

So for example if;

<body class="home">

Then a div would display as follows;

<div><p>This is the Home page</p></div>

Like I said, I don't even know if this is possible but any help would be greatly appreciated. Thanks

5
  • 4
    Where does that <div> come from? Since you're usually creating the HTML together with the PHP code, why do you need this kind of introspection? Commented Jan 12, 2012 at 9:35
  • 1
    Why would you like to do something like that? Could you put a Case Use example? Commented Jan 12, 2012 at 9:36
  • I am using Joomla, if the page class suffix changes (depending on what page you are on) then I want the layout to change. I am already suing template overrides and I don't want to create a completely different template depending on the page. Commented Jan 12, 2012 at 9:48
  • Sounds like a job for a HTML output post-processing filter, no idea if Joomla has something like that. Commented Jan 12, 2012 at 10:01
  • 1
    I have figured it out; <?php if ($this->params->get('pageclass_sfx') == 'home') : ?> I realise that this answer directly relates to Joomla only though. Cheers for your help. Commented Jan 12, 2012 at 10:15

3 Answers 3

1

What you're trying to do can be done with Javascript, but if you want to use php only, then try to use php before you provide the "class" parameter. For example, if $_GET['class']=="home" then <div class="<? echo $_GET['class']?>">some text</div>

Perhaps, you can use Javascript, with IDs for example:

<div id="home"></div>

<script>document.getElementById('home').InnerHTML = "this is text for home";</script>

Hope it helps!

Sign up to request clarification or add additional context in comments.

Comments

0

See you point, but you goes the wrong way. If you want to put all content in one page differs by some query param, there is no need to do so. You just can hide unneeded blocks with css and show them with js. On the other hand, if this is some sort of server-side utilization, there is definitely no reason to do so too. On the server you can totally control the output, so make separate templates.

Comments

0

Is there a reason not to use PHP instead of reading the class of a div?

#index.html
<html>
<?php include /contentDefinitions.php; ?>
...
<?php $content = home; ?>
...
</html>

#contentDefinitions.php
<?php
  if($content = home){
    <p>This is the homepage. I am a happy paragraph.</p>
  }
?>

**this would be a little more efficient with an array or something,
but at the end of the day the easiest thing would just be to include
home.php, page2.php, page3.php etc. as needed instead of going the
route of variables etc... though having an array would let you edit
all the content within one file.

I'm no master of code and have zero familiarity with Joomla, so this may be absolutely useless to you. :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.