need some help with custom article fields

Your code modifications and patches you want to share with others.
Locked
teapotbag
Joomla! Intern
Joomla! Intern
Posts: 74
Joined: Mon Nov 08, 2010 2:39 am

need some help with custom article fields

Post by teapotbag » Sat Dec 04, 2010 8:19 pm

Using this post's advice I've managed to successfully add three extra fields to the article submission form in both the frontend and the backend.

However, I'm having trouble with their styling.

In the templates/mytemplate/html/com_content/article/default.php I have included the fields using this code:

Code: Select all

 <span class="eventinfo">
<?php echo $this->escape($this->article->eventdate); ?> |
<?php echo $this->escape($this->article->eventtime); ?> |
<?php echo $this->escape($this->article->eventlocation); ?>
</span> 
The idea being that the span class puts a border around these three strings of info so they end up looking like this:

Image

However, if nothing is entered into those fields (and they are not mandatory) the problem is that the span class and the dividers still get generated and it looks like this:

Image


So what I would need is some way to make the span tag and the dividers only load IF any of the fields have been filled out.

How do I do this? It MUST be possible.
Last edited by teapotbag on Sat Dec 04, 2010 9:36 pm, edited 1 time in total.

User avatar
RussW
Joomla! Exemplar
Joomla! Exemplar
Posts: 9352
Joined: Sun Oct 22, 2006 4:42 am
Location: Sunshine Coast, Queensland, Australia
Contact:

Re: need some help with custom article fields

Post by RussW » Sat Dec 04, 2010 9:11 pm

Try something like this; I've not tested or even tried this, so it might not be 100% correct syntax-wise, but you want to use an "if' statement to only display things if they are present.

Code: Select all

<?php if($this->article->eventdate || $this->article->eventtime || $this->article->eventlocation) : ?>

  <span class="eventinfo">
     <?php echo $this->escape($this->article->eventdate); ?> |
     <?php echo $this->escape($this->article->eventtime); ?> |
     <?php echo $this->escape($this->article->eventlocation); ?>
  </span>

<?php endif; ?>
You may also want to add "if" statements to each field display, so if only 1 or 2 of the fields are completed, then the empty field wont display.
Joomla! on the fabulous Sunshine Coast...
hotmango, web & print http://www.hotmango.me/
The Styleguyz https://www.thestyleguyz.com/

teapotbag
Joomla! Intern
Joomla! Intern
Posts: 74
Joined: Mon Nov 08, 2010 2:39 am

Re: need some help with custom article fields

Post by teapotbag » Sat Dec 04, 2010 9:27 pm

That works! Thank you SO MUCH! That's exactly what I was looking for! Cos see I'm not familiar with php syntax, I knew it had to be something like that but I had no idea to write it.

Ok, solved! :D


ps.
and yeah actually you're right, also to avoid loading separators for nothing, I did it like this in the end:

Code: Select all

<?php if($this->article->eventdate || $this->article->eventtime || $this->article->eventlocation) : ?>
	<span class="eventinfo">
                 <?php echo $this->escape($this->article->eventdate); ?> 
        
                 <?php if($this->article->eventtime) : ?>
                        | <?php echo $this->escape($this->article->eventtime); ?> 
                 <?php endif; ?>
         
                 <?php if($this->article->eventlocation) : ?>
                        | <?php echo $this->escape($this->article->eventlocation); ?>
                 <?php endif; ?>
	</span> 
       <br /><br />
<?php endif; ?>
Awesome! Thanks a lot!


Locked

Return to “Core Hacks and Patches”