Answer the question
In order to leave comments, you need to log in
Is it possible to replace one variable with different values from an array when displaying text?
Maybe I wrote the title incorrectly, I'm sorry =)
The situation is this, you need to do something like that .
I am writing a site on a framework and I have an item and associated photos with it (items_photos) can I make it so that I insert {photo 1} into the editor and when displayed on the site, the first associated image is displayed in this place, etc.
Or consider another option.
PS: Inserting photos through the editor is not suitable.
Answer the question
In order to leave comments, you need to log in
Question removed.
Solved using php.
searched in the text [photo 1][photo 2], etc.
if(preg_match_all("/\[photo([^\[\]]*)\]/", $text, $preg, PREG_PATTERN_ORDER)){
foreach($preg[0] as $key => $value){
$i = $preg[1][$key];
//$photos - массив с картинками
if( $photos[$i-1]['file'] ){
$block = "<div><img src="'.$photos[$i-1]['file'],.'"></div>';
}else{
$block = ' ';
}
$text = str_replace($value, $block, $text);
}
}
What does it mean to write in a framework?
Everyone writes in frameworks these days. It's just that some people mean wordpress, some symphonies, some php modules, some wrappers over cgi, and so on.
You didn't provide any information at all. In its simplest form, you can do something like {{item->items_photos.first()}}, and in the output, anything wrapped in {{}} is passed to eval().
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question