Skip to content

Changing file extension to .php doesn't seem to support PHP tags #11575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JohnnyWalkerDigital opened this issue Mar 13, 2025 · 2 comments
Closed

Comments

@JohnnyWalkerDigital
Copy link

JohnnyWalkerDigital commented Mar 13, 2025

Bug description

v5.50.0

According to the documentation, if you change your view's file extension from .antlers.html to .antlers.php you can write all the raw PHP you want using native PHP tags. However I tried this with a view and the PHP tags within the document are rendered as HTML.

For example:

<?php
  if (!isset($_GET["new"])) {
?>

is in the HTML output as

<!--?php
  if (!isset($_GET["new"])) {
?-->

How to reproduce

  1. Change file extension of a view from .antlers.html to .antlers.php
  2. Add <?php ?> tags to the beginning of the file
  3. Preview the output in your browser

Logs

Environment

Environment
Application Name: PRIVATE
Laravel Version: 11.44.2
PHP Version: 8.4.3
Composer Version: 2.8.6
Environment: local
Debug Mode: ENABLED
URL: www.private.test
Maintenance Mode: OFF
Timezone: UTC
Locale: en

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: file
Database: mysql
Logs: stack / single, slack
Mail: smtp
Queue: sync
Session: file

Statamic
Addons: 4
Sites: 1
Stache Watcher: Enabled
Static Caching: Disabled
Version: 5.50.0 PRO

Statamic Addons
statamic/eloquent-driver: 4.20.2
statamic/ssg: 3.1.1
stillat/antlers-layouts: 2.1.0
visuellverstehen/statamic-classify: 3.0.0

Statamic Eloquent Driver
Asset Containers: eloquent
Assets: eloquent
Blueprints: eloquent
Collection Trees: eloquent
Collections: eloquent
Entries: eloquent
Forms: eloquent
Global Sets: eloquent
Global Variables: eloquent
Navigation Trees: eloquent
Navigations: eloquent
Revisions: file
Sites: eloquent
Taxonomies: eloquent
Terms: eloquent
Tokens: eloquent

Installation

Fresh statamic/statamic site via CLI

Additional details

No response

@duncanmcclean
Copy link
Member

Hmm, your code is working fine for me (provided I add a closing <?php } ?> somewhere). How are you using the .antlers.php file - as a layout/template/partial?

While you can use raw PHP in Antlers templates like that, for something simple like checking a GET parameter, I'd use Statamic's get variable instead:

{{ if !get:new }}
    Your code here...
{{ /if }}

@duncanmcclean
Copy link
Member

Since I'm unable to reproduce your issue, and I haven't heard back in a while, I'm going to close this issue for now. You can use the get variable to access query parameters in your templates.

If you're still running into issue with PHP in Antlers, please let us know how you're using the Antlers view (eg. as a layout/template/partial), and we can take another look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants