Skip to content

Commit

Permalink
imp(playground): display (adaptable) preview only when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
Kocal committed Dec 5, 2023
1 parent 05520e1 commit 5e9edb5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/Form/Type/PlaygroundType.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('url', TextType::class, [
'required' => true,
'label' => 'Page URL',
'required' => false,
])
->add('format', ChoiceType::class, [
'required' => true,
'label' => 'Format',
'empty_data' => 'image',
'choices' => [
Expand Down
24 changes: 16 additions & 8 deletions templates/home/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,27 @@
{{ form_start(form, { attr: { novalidate: 'novalidate' }}) }}
{{ form_row(form.url) }}
{{ form_row(form.format) }}
<button type="submit" class="btn btn-primary">Create</button>
<button type="submit" class="btn btn-primary">
Create
</button>
{{ form_end(form) }}
</div>
<div class="col">
<iframe width="100%" style="aspect-ratio: 1200 / 630" src="{{ image_url }}" class="shadow-sm"></iframe>
{% if form.url.vars.data %}
<div class="col">
{% if form.format.vars.data == 'image' %}
<img src="{{ image_url }}" width="100%" style="aspect-ratio: 1200 / 630" class="shadow-sm"></img>
{% else %}
<iframe src="{{ image_url }}" width="100%" style="aspect-ratio: 1200 / 630" class="shadow-sm"></iframe>
{% endif %}

<hr>
<hr>

<div class="form-group">
<label for="image_url">Open Graph Image URL (preview) </label>
<input type="text" class="form-control" id="image_url" value="{{ image_url }}" readonly>
<div class="form-group">
<label for="image_url">Open Graph Image URL (preview) </label>
<input type="text" class="form-control" id="image_url" value="{{ image_url }}" readonly>
</div>
</div>
</div>
{% endif %}
</div>
</div>
{% endblock %}

0 comments on commit 5e9edb5

Please sign in to comment.