简体   繁体   中英

joomla custom field markup php

I've been working with Joomla's custom fields in an article override, but I'm not having any luck adding markup ONLY when a field is used. I have very limited knowledge of PHP.

Here's my statement:

<?php if(isset($this->item->jcfields[x]) === true  && empty($this->item->jcfields[x]) === false): ?>
    <div class="name"><?php echo $this->item->jcfields[x]->value; ?></div>
<?php endif; ?>

In my limited understanding this would seem to check if the field has content and is not empty. If true, display the second line that wraps the field value in a div. That works.

Conversely, if the field is empty, the second line should be skipped, which would not create the wrapping div.

In reality, the div is created either way.

What am I missing?

I went a different way since Joomla fields didn't register the output as empty with the above code.

Instead, I retrieved the value of the field and searched the text:

    <?php 
        $word = "https";
        $mystring = ($this->item->jcfields[x]->value);
        if(strpos($mystring, $word) == false){echo "";
            } else{
        echo "<div class='facebook-link'>" . $mystring . "</div>";
        }
    ?>

Combined with this CSS:

.facebook-link a  {font-size: 25px; display: inline-block; text-indent: -999em; text-decoration:none;}
.facebook-link a:after {font-family: "FontAwesome"; display: block; text-indent: 0;content: "\f09a";}

The PHP code was added to an article override and wrapped in an outer wrapper that was designated as a css-grid with the grid-template-columns set to repeat{8, 40px).

The end result is a row of linked icons for whatever social media accounts the page user defines.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM