variables are echoing out
-
i have some variablle like this
$image1 = block_field( ‘image-1’ );
$image2 = block_field( ‘image-2’ );
$image3 = block_field( ‘image-3’ );these keep showing up on screen even when i use them in an if statement i have tried
$image2 = block_value( ‘image-2’ );
but this just returns a number no the actual valueany suggestion on how to fix this
-
Hi @alienfactory,
Thanks for bringing this up.Could you try using
block_value()instead?Like:
$image1 = block_value( ‘image-1’ ); ...Because
block_field()echoes the value.yes i tried thqt and it returns 56 not that actual value which is a image url
@alienfactory,
OK, could you please copy the entire template here?If this needs to do something like:
$image1 = block_value( ‘image-1’ ); if ( $image1 ) { echo $image1; }…then maybe it could change the echo statement to use
block_field():$image1 = block_value( ‘image-1’ ); if ( $image1 ) { block_field( 'image-1' ); }here is my full code i dont seem to have any issue with the videourl which is just a text input type. the image1 is a image field type which is giving me the problems
if i echo the variables i get this. the video urls look goos but image varialbes return number
564340http: //www.youtube.com/embed/cbdAOYfsY2ohttp://www.alienfactory.comhttp://goolge.com<?php $image1 = block_value( 'image-1' ); $image2 = block_value( 'image-2' ); $image3 = block_value( 'image-3' ); $videourl1 = block_value( 'videourl1' ); $videourl2 = block_value( 'videourl2' ); $videourl3 = block_value( 'videourl3' ); if( $image1 && $image2 == true ){ ?> <!-- <p><?php echo $image1.$image2.$image3.$videourl1 ?></p> --> <div id="carousel-example-generic" class="carousel slide" data-ride="carousel" data-interval="7000"> <!-- Indicators --> <ol class="carousel-indicators"> <li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li> <li data-target="#carousel-example-generic" data-slide-to="1"></li> <li data-target="#carousel-example-generic" data-slide-to="2"></li> </ol> <!-- Wrapper for slides --> <div class="carousel-inner"> <div class="item active"> <img src="<?php echo $image1; ?>" alt="..."> <div class="carousel-caption"> <?php if($videourl1){ echo '<a href="'.$videourl1.'" class="linkbuttonplay" id="video">WATCH VIDEO</a>'; } ?> </div> </div> <div class="item"> <img src="<?php echo $image2; ?>" alt="..."> <div class="carousel-caption"> <?php if($videourl2){ echo '<a href="'.$videourl2.'" class="linkbuttonplay" id="video">WATCH VIDEO</a>'; } ?> </div> </div> <div class="item"> <img src="<?php echo $image3; ?>" alt="..."> <div class="carousel-caption"> <?php if($videourl3){ echo '<a href="'.$videourl2.'" class="linkbuttonplay" id="video">WATCH VIDEO</a>'; } ?> </div> </div> </div> </div> <?php } else { ?> <div>showme a single image</div> <? } ?>-
This reply was modified 6 years ago by
alienfactory.
Thanks for the template!
How about:
diff --git a/block-mock-image.php b/block-mock-image.php index 0a695f3..d2152fb 100644 --- a/block-mock-image.php +++ b/block-mock-image.php @@ -3,7 +3,8 @@ - $image1 = block_value( 'image-1' ); + $image_1_attachment = wp_get_attachment_image_src( block_value( 'image-1' ), 'full' ); + $image1 = ! empty( $image_1_attachment[0] ) ? $image_1_attachment[0] : '';That’s essentially doing what
block_field( 'image-1' )does:
https://github.com/getblocklab/block-lab/blob/693c950aac4c7946be6efb1dae5d41af26f5d959/php/blocks/controls/class-image.php#L72-L73Awesome that worked Thanks!
I am a bit confused how is it possible that a variable is echoing out with out any print or echo statement
Nice, glad that worked.
Yeah,
block_field()both echoes and returns a value, it’s confusing.I opened a PR for it:
https://github.com/getblocklab/block-lab/pull/517 -
This reply was modified 6 years ago by
The topic ‘variables are echoing out’ is closed to new replies.