antknight Posted November 27, 2012 Share Posted November 27, 2012 First question. How does PW deal with empty fields? Second question. I have made a repeater for a slideshow where you can set image, delay and caption. I only want the h6 to display if there are actually items in the repeater. How can I test for this? <h6>Images</h6> <?php foreach($page->gallery as $slide) { echo "<a rel='prettyPhoto[pp_gal]' title='{$slide->gallery_caption}' href='{$slide->gallery_image->url}'> <img class='peKbGallery' data-delay='{$slide->gallery_delay}' src='{$slide->gallery_image->url}' alt='{$slide->gallery_caption} (Click to enlarge)' /> </a>"; } ?> Thanks! Link to comment Share on other sites More sharing options...
Exceptionz Project Posted November 27, 2012 Share Posted November 27, 2012 You could use the count function: if(count($page->gallery)) { // here your code (for displaying h6 ...) } else { // ... } For more information look at here http://processwire.c...ypes/repeaters/ or here http://processwire.c...pi/arrays/page/ The value of a repeater field is a PageArray. As a result, you may interact with them exactly like you would any other group of pages in ProcessWire. 1 Link to comment Share on other sites More sharing options...
diogo Posted November 27, 2012 Share Posted November 27, 2012 First question. How does PW deal with empty fields? if($page->body){ //not empty }else{ //empty } other options if($page->body) echo "body not empty"; if(!$page->body) echo "body empty"; for the second question: <?php if($page->gallery->count() > 0){?> <h6>Images</h6> <?php foreach($page->gallery as $slide) { echo "<a rel='prettyPhoto[pp_gal]' title='{$slide->gallery_caption}' href='{$slide->gallery_image->url}'> <img class='peKbGallery' data-delay='{$slide->gallery_delay}' src='{$slide->gallery_image->url}' alt='{$slide->gallery_caption} (Click to enlarge)' /> </a>"; } } ?> 2 Link to comment Share on other sites More sharing options...
Soma Posted November 27, 2012 Share Posted November 27, 2012 Some PW template syntax to the table? <? if(count($page->gallery)): ?> <h6>Images</h6> <? foreach($page->gallery as $slide): ?> <a rel='prettyPhoto[pp_gal]' title='<?= $slide->gallery_caption ?>' href='<?= $slide->gallery_image->url ?>'> <img class='peKbGallery' data-delay='<?= $slide->gallery_delay ?>' src='<?= $slide->gallery_image->url ?>' alt='<?= $slide->gallery_caption ?> (Click to enlarge)' /> </a>"; <? endforeach; ?> <? endif; ?> 1 Link to comment Share on other sites More sharing options...
antknight Posted November 27, 2012 Author Share Posted November 27, 2012 Thanks! I did try if(count($page->gallery_image)) { but that didn't work... Can you explain what you mean by Some PW template syntax to the table? Are you referring to this? http://processwire.c...why-php-syntax/ Link to comment Share on other sites More sharing options...
ryan Posted November 27, 2012 Share Posted November 27, 2012 if(count($page->gallery_image)) didn't work, I'm guessing gallery_image is not a repeater field? Try this to see what you get: echo "<pre>gallery_image is: "; if(is_object($page->gallery_image)) { echo "object of type " . get_class($page->gallery_image); if(WireArray::iterable($page->gallery_image)) { echo " with " . count($page->gallery_image) . " items"; } } else { var_dump($page->gallery_image); } echo "</pre>"; Link to comment Share on other sites More sharing options...
diogo Posted November 27, 2012 Share Posted November 27, 2012 Can you explain what you mean by Quote Some PW template syntax to the table? Are you referring to this? http://processwire.c...why-php-syntax/ Yes, but I think Soma is reporting to this post from Apeisa http://processwire.c...ine/#entry12629 I tried to answer without modifying your code too much, but I admit it came out kind of ugly. Soma's code is much better edit: also, if someone has troubles to understand these <? if(count($page->gallery)): ?> , <? endif; ?>, just have a look here http://php.net/manua...tive-syntax.php 1 Link to comment Share on other sites More sharing options...
antknight Posted November 27, 2012 Author Share Posted November 27, 2012 gallery_image is a field within a repeater which is populated. That code returns gallery_image is: NULL. Also, I used a tinymce textarea to enable multiple youtube video embeds, best way to do that you think? I couldn't think how else to do it, but it does rely on them pasting each video link in a separate paragraph... Link to comment Share on other sites More sharing options...
diogo Posted November 27, 2012 Share Posted November 27, 2012 Also, I used a tinymce textarea to enable multiple youtube video embeds, best way to do that you think? I think in this case a repeatable would be more friendly Link to comment Share on other sites More sharing options...
antknight Posted November 27, 2012 Author Share Posted November 27, 2012 I think in this case a repeatable would be more friendly I agree, but with what fieldtype? URL? Then how to embed the video? They would have to copy the embed URL with the correct size from youtube. It would be good if the youtube video embed module worked with URL field Link to comment Share on other sites More sharing options...
diogo Posted November 27, 2012 Share Posted November 27, 2012 I agree, but with what fieldtype? You have many options, can even be a text field. If you ask for the entire URL, You just have to output like this: <iframe width="420" height="315" src="<?=$repeater->video?>"></iframe> If you ask for the video ID, do this instead: <iframe width="420" height="315" src="https://www.youtube.com/embed/<?=$repeater->video?>"></iframe> There is also a module for this http://modules.proce...er-video-embed/ 1 Link to comment Share on other sites More sharing options...
antknight Posted November 28, 2012 Author Share Posted November 28, 2012 Some good options there. Thanks. I am using the module at the moment but only works with a tinymce enabled textarea? Link to comment Share on other sites More sharing options...
diogo Posted November 28, 2012 Share Posted November 28, 2012 Never used it myself, but since it's a text formatter module it should work also in any text field. On the field options, go to the "details" tab, and add it from the text formatters dropdown. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now