Search the Community
Showing results for tags 'else'.
-
I was trying to fix an error earlier which was preventing a series of if statements from working. Basically I have a button called "Product Drawing" which needs localising depending on the current language session. Eventually got it working - I had a bracket in the wrong place. Curious as to why both these work though. On the sample below. each echo is surrounded by curly braces. <?php if ($page->files->count()) foreach($page->files->findTag('drawing') as $file) { if($user->language->name == 'default') {echo "<a href='$file->url' class='uk-button uk-button-primary'>Product drawing</a>";} if($user->language->name == 'french') {echo "<a href='$file->url' class='uk-button uk-button-primary'>Le plan du produit</a>";} if($user->language->name == 'german') {echo "<a href='$file->url' class='uk-button uk-button-primary'>Produktzeichnung</a>";} if($user->language->name == 'spanish') {echo "<a href='$file->url' class='uk-button uk-button-primary'>El dibujo del producto</a>";} if($user->language->name == 'italian') {echo "<a href='$file->url' class='uk-button uk-button-primary'>Il disegno del prodotto</a>";} } ?> On the sample below, there are no curly braces around the echo <?php if ($page->files->count()) foreach($page->files->findTag('breakingreport') as $file) { if($user->language->name == 'default') echo "<a href='$file->url' class='uk-button uk-button-primary'>Breaking strain report</a>"; if($user->language->name == 'french') echo "<a href='$file->url' class='uk-button uk-button-primary'>Le test de rupture</a>"; if($user->language->name == 'german') echo "<a href='$file->url' class='uk-button uk-button-primary'>Bruchfestigkeit bericht</a>"; if($user->language->name == 'spanish') echo "<a href='$file->url' class='uk-button uk-button-primary'>Informe resistencia</a>"; if($user->language->name == 'italian') echo "<a href='$file->url' class='uk-button uk-button-primary'>La rottura rapporto ceppo</a>"; } ?> Should the second piece work?
- 15 replies
-
i have a repeater with 2 fields – image – text if there are images uploaded then the output should be only the image field. if no images uploaded, then only the text-field should be shown right now, if the image-field is empty and the text-field is filled. i'm getting two boxes. and the first one is empty. <?php foreach($page->repeater as $box) { if($box->images) { ?> <div class="box images"> <?php foreach($box->images as $image) { echo "<img src='$image->url'/>"; } ?> </div> <?php } else { } if($box->text) { ?> <div class="box text"><?php echo $box->text; ?></div> <?php } } ?>
-
Hi, this is probably very easy to solve but I just can get the right output. This is the code: <?php //$tender_open is checkbox field; $tenders = $pages->find("template=tender, sort=-created, tender_open=$open"); ?> <h3>Tenders</h3> <?php if($open == 0) { echo '<p>There are no tenders available !</p>'; } else { ?> <ul class="no-style"> <?php foreach ($tenders as $t) { ?> <li> <a href="<?php echo $t->url; ?>"><?php echo $t->title; ?></a> <br> <p>Status: <span class="open">Open</span></p> </li> <?php } ?> </ul> <?php } ?> This is the snippet from the homepage. The code should check if there is an open tender available, if true = display it and if false just output echo "There are no tenders available". Tenders are on separate page tree with their own template. I must be doing something wrong here! Help.