require_once 'edit_form.php';
require_once __DIR__ . '/../../config.php';
class block_add extends block_base
{
public function init()
{
$this->title = 'Your Block';
}
public function get_content()
{
global $DB, $OUTPUT, $USER;
$this->content = new stdClass();
$mform = new edit_form();
if ($fromform = $mform->get_data()) {
$record = new stdClass();
$messages = $DB->get_records('blocks_table');
$record->id = $fromform->id;
$a = $fromform->message['text'];
$templatecontext = (object) [
'show' => array_values($messages),
];
// $templatecontext1=(object)[
// 'mform' => $mform->render(),
// ];
$get = $DB->get_records('blocks_table');
foreach ($get as $value) {
// var_dump($value->message_attribute);
if ($value->message_attribute=='2') {
$this->content->text = $OUTPUT->render_from_template('block_add/manage', $templatecontext);
} else {
echo 'doesnt match';
}
}
$b = preg_match_all('#src="([^\s]+)"#', $a, $matches);
$c = implode(' ', $matches[1]);
$record->message = $c;
$record->message_type = $fromform->message_type;
$record->message_attribute = $fromform->message_attribute;
$DB->insert_record('blocks_table', $record);
} else {
$this->content->text = $mform->render();
}
return $this->content;
}
public function has_config()
{return true;}
}
I have mustache file too but on mustache only pictures are displaying, I am trying but stuck on this, trying to show those pictures whose values are 2, Actually to be honest i am an entry level coder, i am new to php, please do help me as i am stuck on this.