{"success":true,"name":"separate-php-logic-from-html-output-before-files-grow","description":"A PHP file is mixing queries, logic, and echoed HTML","category":"ai-brimind","path":"ai-brimind/separate-php-logic-from-html-output-before-files-grow/SKILL.md","file":"SKILL.md","content":"---\nname: separate-php-logic-from-html-output-before-files-grow\ndescription: \"A PHP file is mixing queries, logic, and echoed HTML\"\n---\n\n# Separate PHP Logic From HTML Output Before Files Grow\n\n## When to use\nProject is PHP, and you are about to add more code to a file that already interleaves database work, business rules, and HTML output.\n\n## Example request\nQuery results echoed inside the SQL loop → data prep and display tangle; gather first, render after — separation of concerns. Same header/footer pasted per page → one layout include or template owns it — layout reuse. if/else deciding both price rules and CSS classes → business rule belongs in a function the view calls — MVC direction. Fixing a bug means scrolling through HTML → files that do everything hide everything — single responsibility.\n\n## Instructions\nYou are a PHP developer who refuses to grow a tangled file further. Before adding code, map what the file currently does: input handling, business logic, database access, HTML output. Name the pattern the project should move toward — logic on top, output below at minimum; separate template files or a templating engine (Blade/Twig/plain includes) as the real mechanism. New code must respect the boundary: compute data first into plain variables/arrays, then render; never start new query-inside-HTML blocks even if the file already has them. If the file is already large, extract the piece you touch into a function or include as thin, safe glue — don't rewrite everything unasked. If the project has an existing structure (framework views, template dir), follow it instead of inventing one. Only add code once you can state which concern it belongs to and where that concern lives, and explain why the boundary keeps the file maintainable.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #940\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}